using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class app_frame_Default2 : System.Web.UI.Page
{
    HtmlForm frmObj;
    DynamicDisplayI DDI;
    string[,] controlarr;

    bool IsEdit = false;
    bool IsCopy = false;
    string strPageKey = "";

    HDDatabase HDD;

    int intRowCnt = 0;
    int intDelCnt = 0;
    int intEventRowCnt = 1;
    int intEventDelCnt = 0;

    int intChildRowCnt = 1;
    int intChildDelCnt = 0;

    public string strPagesetRowID = "";

    DataTable dtaData = new DataTable();
    DataSet dsePageInfo = new DataSet();
    DataSet dseInputInfo = new DataSet();
    DataTable dt_default_col = new DataTable();

    DataSet dseObjectInputInfo = new DataSet();
    DataSet dsePageInputInfo = new DataSet();
    DataSet dsePagesetInputInfo = new DataSet();

    ArrayList defaultColumns;
    private Label lblMessage = null;
    bool isDroplistExists = false; // Added by 'Imran Gani' on 26-Dec-2013, for droplist values.
    protected void Page_PreInit(object sender, EventArgs e)
    {
        this.Theme = Session["Theme"].ToString();
        this.Title = "MaxBlox";
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        lblMessage = getMessageLabel();
        //if (Session["dseObjectInputInfo"] != null)
        //    if (!IsPostBack)
        //        Response.Redirect(Request.UrlReferrer.ToString());
        
        security hdds = new security();
        if (Session["userid"] == null) Response.Redirect(hdds.SessionExpiryURL);
        if (Session["userid"].ToString() == "") Response.Redirect(hdds.SessionExpiryURL);

        //Code added by Sampath on 16-Nov-2011 for IPP Vertical privilege
        if (Request.QueryString["mn"] != null)
        {
            if (!hdds.checkObjectMenuAccess(Request.QueryString["mn"]))
            {
                lblMessages.Text = wrapItAsMessageNew("<img src=\"Images/info.gif\" alt=\"\"></img>&nbsp;You do not have sufficient access permission.", true);
                pagewizard.Visible = false;
                return;
            }
        }

        //Code added by Sampath on 15-Nov-2011 for IPP Vertical privilege
        if (Request.QueryString["PK"] != null && Request.QueryString["pgs_id"] != null)
        {
            if (!hdds.checkRecordAccess(Request.QueryString["PK"].ToString(), Request.QueryString["pgs_id"].ToString()))
            {
                lblMessages.Text = wrapItAsMessageNew("<img src=\"Images/info.gif\" alt=\"\"></img>&nbsp;You do not have sufficient access permission.", true);
                pagewizard.Visible = false;
                return;
            }
        }


        HDD = new HDDatabase();
        ScreenReader SR = new ScreenReader();
        if (this.Master.FindControl("Form1") != null)
        {
            frmObj = (HtmlForm)this.Master.FindControl("Form1");
        }
        pagewizard.DisplaySideBar = false;

        if (Request.QueryString["PK"] != null)
        {

            pagewizard.HeaderText = "Page Wizard - Edit";
            getpageicons();

            IsEdit = true;
            strPageKey = HDD.GetColumnValue("sy_pgs", "pageset_id", "af_row_id = '" + Request.QueryString["PK"].ToString() + "'");
        }
        if (Request.QueryString["CPY"] != null)
        {
            pagewizard.HeaderText = "Page Wizard - Copy";
            getpageicons();
            IsCopy = true;
        }
        if (!Page.IsPostBack)
        {
            //loadOwneridDropDown();
            owner_id.Value = Session["user_afrowid"].ToString();
            txt_owner_id.Text = Session["userid"].ToString();
        }
        if (Request.QueryString["PK"] == null)
        {
            if (!Page.IsPostBack)
            {
                getpageicons();
            }
        }
        
        LoadControlsArray();
        
        LoadScriptArray();
       
        createDefaultColumns();

        CheckForChangeOwner();

       
        // Added by srivatsan
        ddpageicon.Attributes.Add("OnChange", "showpageicon();");

        //LoadWizardPageModeValues(); //Added By Dhanapal.

        if (!IsPostBack)
        {
           // LoadWizardPageModeValues();
            disableTreeandCategoryview("ALL");
        }

        if (IsEdit && !IsCopy)
        {
            if (Page.IsPostBack == false)
            {
                if (IsCopy == true)
                {
                    ps_rowkey.Value = SR.getHashKey();
                }
                else
                {
                    ps_rowkey.Value = Request.QueryString["PK"].ToString();
                }
                pg_rowkey.Value = HDD.GetColumnValue("Select sy_pg.af_row_id from sy_pg inner join sy_pgs_mem on sy_pg.page_id = sy_pgs_mem.page_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'");
                obj_rowkey.Value = HDD.GetColumnValue("Select sy_obj.af_row_id from sy_obj inner join sy_pgs_mem on sy_obj.object_id = sy_pgs_mem.object_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'");
                ps_id.Value = strPageKey;
                pg_id.Value = HDD.GetColumnValue("Select sy_pg.page_id from sy_pg inner join sy_pgs_mem on sy_pg.page_id = sy_pgs_mem.page_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'");
                obj_id.Value = HDD.GetColumnValue("Select sy_obj.object_id from sy_obj inner join sy_pgs_mem on sy_obj.object_id = sy_pgs_mem.object_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'");
                obj_bu_id.Value = HDD.GetColumnValue("Select sy_obj.object_table from sy_obj inner join sy_pgs_mem on sy_obj.object_id = sy_pgs_mem.object_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'");
                ddtemp.SelectedValue = HDD.GetColumnValue("Select sy_pg.page_view from sy_pg inner join sy_pgs_mem on sy_pg.page_id = sy_pgs_mem.page_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'");
                txt_page_tooltip.Text = HDD.GetColumnValue("Select sy_pg.page_desc from sy_pg inner join sy_pgs_mem on sy_pg.page_id = sy_pgs_mem.page_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'");
                ddownerid.SelectedValue = HDD.GetColumnValue("Select sy_pg.owner_id from sy_pg inner join sy_pgs_mem on sy_pg.page_id = sy_pgs_mem.page_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'");
                owner_id.Value = HDD.GetColumnValue("Select sy_pg.owner_id from sy_pg inner join sy_pgs_mem on sy_pg.page_id = sy_pgs_mem.page_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'");
                /*****Added By Dhanapal For Tree View On DEC272010***/
                string stepagesetmodekey = HDD.GetColumnValue("Select sy_pgs_mode.af_row_id from sy_pgs_mode where sy_pgs_mode.pageset_id = '" + Request.QueryString["PK"].ToString() + "' and mode = 'TV'");

                string stePagesetCategorymodekey = HDD.GetColumnValue("Select sy_pgs_mode.af_row_id from sy_pgs_mode where sy_pgs_mode.pageset_id = '" + Request.QueryString["PK"].ToString() + "' and mode = 'CV'"); //Added By Dhanapal On Jan 20 2011
                string stePagesetDatasheetmodekey = HDD.GetColumnValue("Select sy_pgs_mode.af_row_id from sy_pgs_mode where sy_pgs_mode.pageset_id = '" + Request.QueryString["PK"].ToString() + "' and mode = 'DS'"); // Added by 'Imran Gani' (copied from RakaTech) on 27-May-2014, for Datasheet
                  
                LoadWizardPageModeValues();//Added By Dhanapal ON DEC272010


                if (stepagesetmodekey.ToString().Trim() != "")
                    ps_mode_rowkey.Value = stepagesetmodekey;
                else
                    ps_mode_rowkey.Value = SR.getHashKey(); //Added By Dhanapal on DEC272010

                if (stePagesetCategorymodekey.ToString().Trim() != "" )
                    ps_mode_category_rowkey.Value = stePagesetCategorymodekey;
                else
                    ps_mode_category_rowkey.Value = SR.getHashKey();

                if (stePagesetDatasheetmodekey.ToString().Trim() != "") // Added by 'Imran Gani' (copied from RakaTech) on 27-May-2014, for Datasheet
                    ps_mode_datasheet_rowkey.Value = stePagesetDatasheetmodekey;
                else
                    ps_mode_datasheet_rowkey.Value = SR.getHashKey();
                
                LoadEditPage LEP = new LoadEditPage();
                txt_owner_id.Text = LEP.GetUserIDFromAfrowid(owner_id.Value);


                chk_associate_notes.Checked = Convert2Boolean(HDD.GetColumnValue("Select sy_obj.associate_notes from sy_obj inner join sy_pgs_mem on sy_obj.object_id = sy_pgs_mem.object_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'")); //Added by srivatsan for notes changes
                chk_associate_documents.Checked = Convert2Boolean(HDD.GetColumnValue("Select sy_obj.associate_documents from sy_obj inner join sy_pgs_mem on sy_obj.object_id = sy_pgs_mem.object_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'")); //Added by 'Imran Gani' on 14-Sep-12 for documents
                chk_sections_as_tabs.Checked = Convert2Boolean(HDD.GetColumnValue("Select sy_pg.sections_as_tabs from sy_pg inner join sy_pgs_mem on sy_pg.page_id = sy_pgs_mem.page_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'")); //Added by 'Imran Gani' on 31-May-13 for section as tabs
                chk_associate_task.Checked = Convert2Boolean(HDD.GetColumnValue("Select sy_obj.associate_task from sy_obj inner join sy_pgs_mem on sy_obj.object_id = sy_pgs_mem.object_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'")); // Added by 'Imran Gani' (copied from RakaTech) on 05-Sep-2013 for Task & Alerts

                // Added by srivatsan
                string selectedvalue = HDD.GetColumnValue("Select sy_pg.page_icon from sy_pg inner join sy_pgs_mem on sy_pg.page_id = sy_pgs_mem.page_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'");
                if (selectedvalue != "")
                {
                    ddpageicon.SelectedValue = selectedvalue;
                }
                else
                {
                    ddpageicon.SelectedValue = HDD.GetColumnValue("select default_value from sy_pg_ctr where control_attrib_id ='page_icon' and page_id = 'd552d1a32d3d10f9' ");
                }
                GetNextStepValues(); // Added by srivatsan for Next step options

                LoadWizardPageEdit();
            }
        }
        else
        {
            if (Page.IsPostBack == false)
            {
                ps_rowkey.Value = SR.getHashKey();
                pg_rowkey.Value = SR.getHashKey();
                obj_rowkey.Value = SR.getHashKey();
                ps_mode_rowkey.Value = SR.getHashKey(); //Added By Dhanapal DEC272010
                ps_mode_category_rowkey.Value = SR.getHashKey(); // Added By Dhanapal Jan202011
                ps_mode_datasheet_rowkey.Value = SR.getHashKey(); // Added by 'Imran Gani' (copied from RakaTech) on 27-May-2014, for Datasheet

                if (IsCopy)
                {
                    ddtemp.SelectedValue = HDD.GetColumnValue("Select sy_pg.page_view from sy_pg inner join sy_pgs_mem on sy_pg.page_id = sy_pgs_mem.page_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'");
                    ddpageicon.SelectedValue = HDD.GetColumnValue("Select sy_pg.page_icon from sy_pg inner join sy_pgs_mem on sy_pg.page_id = sy_pgs_mem.page_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'");// Added by srivatsan
                    GetNextStepValues(); // Added by srivatsan
                    chk_associate_notes.Checked = Convert2Boolean(HDD.GetColumnValue("Select sy_obj.associate_notes from sy_obj inner join sy_pgs_mem on sy_obj.object_id = sy_pgs_mem.object_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'")); //Added by srivatsan for notes changes
                    chk_associate_documents.Checked = Convert2Boolean(HDD.GetColumnValue("Select sy_obj.associate_documents from sy_obj inner join sy_pgs_mem on sy_obj.object_id = sy_pgs_mem.object_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'")); //Added by 'Imran Gani' on 14-Sep-12 for documents
                    chk_sections_as_tabs.Checked = Convert2Boolean(HDD.GetColumnValue("Select sy_pg.sections_as_tabs from sy_pg inner join sy_pgs_mem on sy_pg.page_id = sy_pgs_mem.page_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'")); //Added by 'Imran Gani' on 31-May-13 for section as tabs
                    chk_associate_task.Checked = Convert2Boolean(HDD.GetColumnValue("Select sy_obj.associate_task from sy_obj inner join sy_pgs_mem on sy_obj.object_id = sy_pgs_mem.object_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'")); // Added by 'Imran Gani' (copied from RakaTech) on 05-Sep-2013 for Task & Alerts
                    // Added by 'Imran Gani' (copied from RakaTech) on 27-May-2014, for Datasheet
                    string strsql = "select spm.af_row_id , spm.mode  from sy_pgs_mode spm where spm.pageset_id = '" + Request.QueryString["PK"].ToString() + "' and spm.mode = 'DS'";
                    DataTable dt = new DataTable();
                    dt = HDD.GetDataTable(strsql);
                    if (dt.Rows.Count > 0)
                    {
                        DataRow[] datasheetfield = dt.Select("mode = 'DS'");
                        if (datasheetfield.Length > 0)
                            ChkDatasheet.Checked = true;
                    }
                }
                else
                {
                    ddpageicon.SelectedValue = HDD.GetColumnValue("select default_value from sy_pg_ctr where page_id = 'd552d1a32d3d10f9' and control_id = 'page_icon'");
                    GetNextStepValues(); // Added by srivatsan
                }
            }
        }

        if (Page.IsPostBack == false)
        {
            GlobalValues.loadwizard = false;
            GlobalValues.loadeventwizard = false;
            GlobalValues.loadchildwizard = false;
            GlobalValues.loadpagemodewizard = false;
            HDD = new HDDatabase();

            DataTable dtaPageChild;
            if ((IsEdit) || (IsCopy))
            {
                string strSql = " Select sy_pg.Page_Name as [Name],sy_pg.Page_id as [Page],sy_pg.object_id as [Object]  " +
                                 " from sy_pg inner join sy_pgs_mem on " +
                                 "sy_pgs_mem.page_id = sy_pg.page_id inner join sy_pgs on sy_pgs.af_row_id = sy_pgs_mem.pageset_id where sy_pgs.pageset_id = '" + strPageKey.Replace("'", "''") + "' order by is_master desc";

                dtaPageChild = HDD.GetDataTable(strSql);
                SelChildPage.DataSource = dtaPageChild;
                SelChildPage.DataTextField = "Name";
                SelChildPage.DataValueField = "Page";
                SelChildPage.DataBind();
            }
        }
        else
        {
        }

        if (IsPostBack)
        {
            LoadDivControls();
        }

        if (Page.IsPostBack != false)
        {
            if (GlobalValues.loadwizard == true)
            {
                dseObjectInputInfo = (DataSet)Session["dseObjectInputInfo"];
                dsePageInputInfo = (DataSet)Session["dsePageInputInfo"];
                dsePagesetInputInfo = (DataSet)Session["dsePagesetInputInfo"];

              
                LoadWizard(false);
                LoadWizardMasterFields();
                LoadWizardPageEvents();
                LoadWizardPageModes();//Added By Dhanapal on DEC232010
                
            }
        }
        isViewMode();
        shownextsteppanel();
    }
    private Label getMessageLabel()//included by sanal on Dec 29, 2010
    {
        DynamicDisplayI ddi = null;
        Label lblRet = new Label();
        try
        {
            ddi = new DynamicDisplayI();
            Control c = ddi.FindControl(pagewizard.Parent.Controls, "lblMessages");
            if (c != null)
            {
                if (c is Label)
                {
                    lblRet = (Label)c;
                }
            }
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error :getMessageLabel " + e.Message);
        }
        finally { ddi = null; }
        return lblRet;
    }
    private void isViewMode()
    {
        if (HttpContext.Current.Request.QueryString["VMODE"] != null)
            if (HttpContext.Current.Request.QueryString["VMODE"] == "1")
            {
                DynamicDisplayI ddi = new DynamicDisplayI();
                ddi.disableControls(this);
                ddi = null;
            }
    }
    private void LoadWizardPageEdit()
    {
        HDD = new HDDatabase();
        DDI = new DynamicDisplayI();
        txtpsid.Text = strPageKey;

        if (Request.QueryString["CPY"] != null)
        {
            txtpsid.Enabled = true;
            txtpsid.Text = "";
            txtpsname.Text = "";
        }
        else
        {
            txtpsid.Enabled = false;
            txtpsname.Text = HDD.GetColumnValue("sy_pgs", "pageset_name", "pageset_id = '" + strPageKey.Replace("'", "''") + "'");
        }


        HtmlInputHidden hihtot = (HtmlInputHidden)DDI.FindControl(frmObj.Controls, "tot_page");
        hihtot.Value = HDD.GetColumnValue("Select count(*) from sy_pgs_mem where pageset_id = '" + strPageKey.Replace("'", "''") + "'");
    }

    private void LoadControlsArray()
    {
        controlarr = new string[,] 
        { 
            {"TB", "txt_control_name","Control Name:",""},
            {"TB", "txt_control_id","Control ID:",""}, //Srivatsan for caption renaming
            {"TB", "txt_seq","Sequence:",""},             
            {"CB", "cb_visible","Visible:",""},
            {"CB", "cb_readonly","Is read only:",""},
            {"CB", "cb_list","Show in list:",""},
            {"DD", "dd_typeobject","Control Type:","37d0291fd176f846"},
            {"TB", "txt_desc","Description:",""},
            {"DD", "dd_datatype","Data Type:","e1d4999d3739f846"},
            {"TB", "txt_size","Size:",""},
            {"TB", "txt_default","Default value:",""},
            {"CB", "cb_unique","Is Unique:",""},
            {"CB", "cb_filter","Filter:",""},
            {"TB", "txt_tooltip","Tooltip:",""},
            {"HC", "att_af_row_id","AttRowID:",""}, 
            {"HC", "ctr_af_row_id","ControlRowID:",""},
            {"DD", "dd_databind","Data bind:","5b6ab4768085c4a1"}, 
            {"DD", "dd_inputmask","Format Mask:","755bbc2bce7aa527"},
            {"CB", "cb_is_section","New Section:",""},//ssks
            {"CB", "cb_is_search","Search:",""},//Added By Dhanapal For Search on Dec 14 2010
            {"DD", "dd_section_name","Section Name:","5001"},//Added By Dhanapal For Section on Nov 30 2010
            {"DD", "dd_field_type","Field Type:","a0f127659617ac6Z"}, // Added By 'Imran Gani' on 15-Jul-2013, For Extended field support
            {"TA", "ta_droplist","Droplist Values:",""}, // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
            {"HC", "att_owner_id","AttOwnerID:",""}, // Added By 'Imran Gani' on 23-Jul-2013, For owner of a page control
            {"HC", "ctr_owner_id","ControlOwnerID:",""}            
        };

        imgbtn_update.TabIndex = (short)(controlarr.Length + 1);
        imgbtn_save.TabIndex = (short)(controlarr.Length + 1);


        if (Page.IsPostBack == false)
        {
            string strSql = "Select * from sy_acr_mem where acr_id  = '438b9d8767ec468a' order by mem_name";
            ddtemp.DataSource = HDD.GetDataTable(strSql);
            ddtemp.DataTextField = "mem_name";
            ddtemp.DataValueField = "mem_id";
            ddtemp.DataBind();
            ddtemp.Items.Add("");
            ddtemp.SelectedValue = "2"; // Added by 'Imran Gani' on 08-Aug-2013, for default page alignment type.

            string strSql1 = "Select * from sy_acr_mem where acr_id  = '5b8347b08c021f59' order by mem_name";
            ddpageicon.DataSource = HDD.GetDataTable(strSql1);
            ddpageicon.DataTextField = "mem_name";
            ddpageicon.DataValueField = "mem_id";
            ddpageicon.DataBind();


            GetNextStepValues(); // Added bys srivatsan
        }
    }

    private void LoadScriptArray()
    {
        LiteralControl lc = new LiteralControl();
        string strarray = "";

        for (int j = 0; j <= controlarr.GetUpperBound(0); j++)
        {
            strarray = strarray + "\"" + controlarr[j, 1].ToString() + "\"" + ",";
        }
        strarray = strarray.TrimEnd(',');
        lc.Text = "<script language='JavaScript' type='text/javascript'> myarr = new Array(" + strarray + ");</script>";
        this.Controls.Add(lc);
    }

    private void LoadDivControls()
    {
        bool divrow = false;
        HDD = new HDDatabase();
        DDI = new DynamicDisplayI();
        Control cc = DDI.FindControl(frmObj.Controls, "dd_section_name");
        HtmlTable divhtObj = (HtmlTable)DDI.FindControl(frmObj.Controls, "div_tbl_cont");
        HtmlTable divhtAdv = (HtmlTable)DDI.FindControl(frmObj.Controls, "div_tbl_adv");
        HtmlTableRow divhtrObj;
        HtmlTableCell divhtcObj;
        string strCtrlType;
        divhtrObj = new HtmlTableRow();

        for (int j = 0; j <= controlarr.GetUpperBound(0); j++)
        {
            if (divrow == true)
            {
                divhtrObj = new HtmlTableRow();
            }

            //if ((controlarr[j, 1].ToString() == "dd_databind"))
            //{
            //    divhtrObj = new HtmlTableRow();
            //}

            Label lbl = new Label();
            lbl.CssClass = "controlLabelFont";
            strCtrlType = controlarr[j, 0].ToString();
            switch (strCtrlType.ToUpper())
            {
                case "DA":
                    break;

                case "DT":
                    break;
                case "HC":

                    divhtcObj = new HtmlTableCell();

                    divhtcObj = new HtmlTableCell();
                    HiddenField hc = new HiddenField();
                    hc.ID = controlarr[j, 1].ToString();
                    divhtcObj.Controls.Add(hc);
                    divhtrObj.Controls.Add(divhtcObj);
                    break;

                case "TB":

                    divhtcObj = new HtmlTableCell();
                    lbl.Text = controlarr[j, 2].ToString();
                    //lbl.Font.Name = "Arial";
                    //lbl.Font.Size = FontUnit.Point(8);
                    lbl.CssClass = "controlLabelFont";
                    if ((controlarr[j, 1].ToString() == "att_af_row_id") || (controlarr[j, 1].ToString() == "ctr_af_row_id"))
                    {
                        lbl.Visible = false;
                    }
                    divhtcObj.Controls.Add(lbl);
                    divhtrObj.Controls.Add(divhtcObj);

                    divhtcObj = new HtmlTableCell();
                    TextBox txt = new TextBox();
                    txt.ID = controlarr[j, 1].ToString();

                    if ((controlarr[j, 1].ToString() == "att_af_row_id") || (controlarr[j, 1].ToString() == "ctr_af_row_id"))
                    {
                        txt.Visible = false;
                    }
                    //txt.Font.Name = "Arial";
                    //txt.Font.Size = FontUnit.Point(8);
                    txt.CssClass = "controlFont";
                    if (controlarr[j, 1].ToString() == "txt_control_name")
                    {
                        //if (Request.QueryString["PK"] == null)
                        //{
                        //txt.Attributes.Add("onblur", "javascript:SetControlName();");
                        txt.Attributes.Add("onblur", "javascript:SetControlID();");

                        //}
                    }
                    divhtcObj.Controls.Add(txt);

                    if (controlarr[j, 1].ToString() == "txt_control_id")
                    {
                        Label vld_controlid = new Label();
                        vld_controlid.ID = "vld_control_id";
                        vld_controlid.Text = " Required Field";
                        vld_controlid.CssClass = "defaultFont";
                        vld_controlid.ForeColor = System.Drawing.Color.Red;
                        vld_controlid.Font.Size = 8;

                        divhtcObj.Controls.Add(vld_controlid);
                    }

                    if (controlarr[j, 1].ToString() == "txt_control_name")
                    {
                        Label vld_controlid = new Label();
                        vld_controlid.ID = "vld";
                        vld_controlid.Text = " Required Field";
                        vld_controlid.CssClass = "defaultFont";
                        vld_controlid.ForeColor = System.Drawing.Color.Red;
                        vld_controlid.Font.Size = 8;

                        divhtcObj.Controls.Add(vld_controlid);
                    }

                    divhtrObj.Controls.Add(divhtcObj);
                    break;

                case "CB":
                    divhtcObj = new HtmlTableCell();
                    lbl.Text = controlarr[j, 2].ToString();
                    divhtcObj.Controls.Add(lbl);
                    divhtrObj.Controls.Add(divhtcObj);

                    divhtcObj = new HtmlTableCell();
                    CheckBox cb = new CheckBox();
                    cb.ID = controlarr[j, 1].ToString();
                    cb.EnableViewState = true;
                    divhtcObj.Controls.Add(cb);
                    divhtrObj.Controls.Add(divhtcObj);

                    break;

                case "DD":
                    string bindid = "";
                    string bindtable = "";
                    string bind_value = "";
                    string bind_text = "";

                    string strSql = "";

                    divhtcObj = new HtmlTableCell();
                    lbl.Text = controlarr[j, 2].ToString();
                    divhtcObj.Controls.Add(lbl);
                    divhtrObj.Controls.Add(divhtcObj);

                    divhtcObj = new HtmlTableCell();
                    DropDownList dd = new DropDownList();
                    dd.ID = controlarr[j, 1].ToString();

                    // dd.Font.Name = "Arial";
                    //dd.Font.Size = FontUnit.Point(8);
                    dd.CssClass = "controlFont";

                    bindtable = HDD.GetColumnValue("sy_bnd", "bind_table", "af_row_id = '" + controlarr[j, 3].ToString() + "'");
                    bindid = HDD.GetColumnValue("sy_bnd", "bind_parameter", "af_row_id = '" + controlarr[j, 3].ToString() + "'");
                    bind_value = HDD.GetColumnValue("sy_bnd", "bind_value", "af_row_id = '" + controlarr[j, 3].ToString() + "'");
                    bind_text = HDD.GetColumnValue("sy_bnd", "bind_text", "af_row_id = '" + controlarr[j, 3].ToString() + "'");



                    strSql = "Select * from " + bindtable;

                    if (bindid != "")
                    {
                        strSql = strSql + " where " + bindid + " order by " + bind_text;
                    }
                    else
                        strSql = strSql + " order by " + bind_text;

                    //switch (bindtable.ToLower())
                    //{
                    //    case "sy_bnd":
                    //        strSql = strSql + " order by bind_name";
                    //        break;
                    //    case "sy_format_masks":
                    //        strSql = strSql + " order by name";
                    //        break;
                    //    case "sy_acr_mem":
                    //        strSql = strSql + " order by mem_name";
                    //        break;
                    //}

                    if (controlarr[j, 1].ToString() == "dd_databind")
                    {
                        strSql = applysecurity(strSql);
                    }

                    DataTable ds = HDD.GetDataTable(strSql);

                    if ((controlarr[j, 1].ToString() == "dd_typeobject") || (controlarr[j, 1].ToString() == "dd_datatype") || (controlarr[j, 1].ToString() == "dd_section_name") || (controlarr[j, 1].ToString() == "dd_field_type")) // Modified By 'Imran Gani' on 15-Jul-2013, For Extended field support
                    {
                    }
                    else
                    {
                        ds.Rows.InsertAt(ds.NewRow(), 0);
                    }

                    if ((controlarr[j, 1].ToString() == "dd_section_name"))//Dhanapal For Section On Dec 2 2010
                    {
                        getandFillSectionCombo(ref divhtcObj, ref dd);

                    }
                    else
                    {
                        dd.DataSource = ds;
                        dd.DataTextField = bind_text;
                        dd.DataValueField = bind_value;
                        dd.SelectedIndex = 0;
                        dd.DataBind();
                    }

                    if (controlarr[j, 1].ToString() == "dd_typeobject")
                    {
                        dd.SelectedValue = "TB";
                    }
                    else if (controlarr[j, 1].ToString() == "dd_datatype")
                    {
                        dd.SelectedValue = "TX";
                    }
                    else if (controlarr[j, 1].ToString() == "dd_field_type") //Added By 'Imran Gani' on 15-Jul-2013, For Extended field support
                    {
                        dd.SelectedValue = "USR";
                        if (Session["user_afrowid"].ToString() != "e51e0327224a2eb9")
                            dd.Enabled = false;
                    }

                    divhtcObj.Controls.Add(dd);
                    divhtrObj.Controls.Add(divhtcObj);
                    break;
                case "TA": // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
                    divhtcObj = new HtmlTableCell();
                    lbl.Text = controlarr[j, 2].ToString();
                    lbl.CssClass = "controlLabelFont";
                    divhtcObj.Align = "left";
                    divhtcObj.VAlign = "top";
                    divhtcObj.Controls.Add(lbl);

                    #region Help Icon and Tooltip
                    Image imgHelp = new Image();
                    imgHelp.AlternateText = "Help";
                    imgHelp.ToolTip = "click here to know more about Droplist.";
                    imgHelp.ImageUrl = "icons/help_on.gif";
                    imgHelp.Attributes.Add("style", "cursor:pointer;");
                    imgHelp.Attributes.Add("onclick", "javascript:document.getElementById('ctl00_ContentPlaceHolder3_div_help_droplist').style.display = 'block';");
                    divhtcObj.Controls.Add(imgHelp);

                    Panel divHelp = new Panel();
                    divHelp.ID = "div_help_droplist";
                    divHelp.Width = 250;
                    divHelp.Height = 80;
                    divHelp.Attributes.Add("style", "display:none; z-index:1; position:absolute; background-color:White; min-width:200px; padding: 0px 0px 0px 0px; border:solid 1px #000000; overflow:auto;");

                    HtmlTable tbHelp = new HtmlTable();
                    tbHelp.Width = "100%";
                    tbHelp.CellPadding = 2;

                    HtmlTableRow trHelp = new HtmlTableRow();
                    HtmlTableCell tdHelp = new HtmlTableCell();
                    imgHelp = new Image();
                    imgHelp.AlternateText = "Close this window";
                    imgHelp.ToolTip = "Close this window.";
                    imgHelp.ImageUrl = "Images/xClose.gif";
                    imgHelp.Attributes.Add("style", "cursor:pointer;");
                    imgHelp.Attributes.Add("onclick", "javascript:document.getElementById('ctl00_ContentPlaceHolder3_div_help_droplist').style.display = 'none';");
                    tdHelp.Controls.Add(imgHelp);
                    trHelp.Align = "right";
                    trHelp.Controls.Add(tdHelp);
                    tbHelp.Controls.Add(trHelp);

                    trHelp = new HtmlTableRow();
                    tdHelp = new HtmlTableCell();
                    Label lblHelp = new Label();
                    lblHelp.CssClass = "controlFont";
                    lblHelp.Text = "It contains a list of values for Droplist.<br/><b>None/Empty</b> text will be consider as empty value.<br/>Droplist does not support <b>Data Bind</b>.";
                    tdHelp.Controls.Add(lblHelp);
                    trHelp.Controls.Add(tdHelp);
                    tbHelp.Controls.Add(trHelp);
                    divHelp.Controls.Add(tbHelp);
                    divhtcObj.Controls.Add(divHelp);
                    divhtrObj.Controls.Add(divhtcObj);
                    #endregion

                    divhtcObj = new HtmlTableCell();
                    TextBox txt_area = new TextBox();
                    txt_area.ID = controlarr[j, 1].ToString();
                    txt_area.CssClass = "controlFont";
                    txt_area.Rows = 3;
                    txt_area.Columns = 17;
                    txt_area.TextMode = TextBoxMode.MultiLine;
                    txt_area.Attributes.Add("style", "height: 50px;");
                    //if (controlarr[j, 1].ToString() == "ta_droplist")
                        //txt_area.Attributes.Add("onblur", "javascript:alert();");
                    divhtcObj.Controls.Add(txt_area);
                    divhtrObj.Controls.Add(divhtcObj);
                    break;
            }

            if ((controlarr[j, 1].ToString() == "dd_databind"))
            {
                divrow = false;
            }
            else if ((controlarr[j, 1].ToString() == "dd_inputmask"))
            {
                divhtAdv.Controls.Add(divhtrObj);
                divrow = true;
            }
            else if ((controlarr[j, 1].ToString() == "cb_is_section"))//ssks
            {
                divhtAdv.Controls.Add(divhtrObj);

                divrow = false;
                //divhtAdv.Border = 1;
            }
            else if ((controlarr[j, 1].ToString() == "dd_section_name"))//Section Name by Dhanapal_nov_30_2010
            {
                divhtAdv.Controls.Add(divhtrObj);
                divrow = false;
                //divhtAdv.Border = 1;
            }
            else if ((controlarr[j, 1].ToString() == "cb_is_search"))//Search By Dhanapal On Dec 14 2010
            {
                divhtAdv.Controls.Add(divhtrObj);
                divrow = true;
            }
            else if ((controlarr[j, 1].ToString() == "dd_field_type")) //Added By 'Imran Gani' on 15-Jul-2013, For Extended field support
            {
                divhtAdv.Controls.Add(divhtrObj);
                divrow = true;
            }
            else if ((controlarr[j, 1].ToString() == "ta_droplist")) // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
            {
                divhtAdv.Controls.Add(divhtrObj);
                divrow = true;
            }
            else if ((controlarr[j, 1].ToString() == "ctr_af_row_id"))
            {
                divhtObj.Controls.Add(divhtrObj);
                divrow = true;
            }
            else
            {
                if ((((j + 1) % 2) != 0) && (j != controlarr.GetUpperBound(0)))
                {
                    divrow = false;
                }
                else
                {
                    divhtObj.Controls.Add(divhtrObj);
                    divrow = true;
                }
            }
        }
    }

    private void getandFillSectionCombo(ref HtmlTableCell divhtcObj, ref DropDownList dd) //Added By Dhanapal For Section on Dec 07 2010
    {

        string strSql = "select distinct section_name from sy_pg_ctr where page_id = '" + pg_rowkey.Value + "' order by section_name";
        DataTable dtaSectionTable = HDD.GetDataTable(strSql);
        if (dtaSectionTable.Rows.Count > 0)
        {
            dd.DataSource = dtaSectionTable;
            dd.DataTextField = "section_name";
            dd.DataValueField = "section_name";
            dd.DataBind();
        }

        dd.Style.Add("display", "none"); //To hide The Select Box  Section Name
        /*****Added By Dhanapal************/
        HtmlInputText htxt = new HtmlInputText();
        htxt.Attributes["class"] = "controlFont";
        htxt.ID = "Tags";
        htxt.MaxLength = 50;
        divhtcObj.Controls.Add(htxt);


    }

    private void LoadHiddenControls(bool bln_update)
    {
        DDI = new DynamicDisplayI();
        string currentpage;
        HtmlInputHidden hihtot = (HtmlInputHidden)DDI.FindControl(frmObj.Controls, "update_page");
        currentpage = hihtot.Value;
        int RowCnt = 0;

        if (bln_update == false)
        {
            HtmlInputHidden hihobj = (HtmlInputHidden)DDI.FindControl(frmObj.Controls, "_sys" + currentpage + "_RowCount");
            int intRowCnt = hihobj.Value == "" ? 1 : Convert.ToInt32(hihobj.Value);
            RowCnt = intRowCnt;
        }
        else
        {
            HtmlInputHidden hihobj = (HtmlInputHidden)DDI.FindControl(frmObj.Controls, "updatecount_" + currentpage);
            RowCnt = hihobj.Value == "" ? 1 : Convert.ToInt32(hihobj.Value);
        }

        HtmlTable htObj = (HtmlTable)DDI.FindControl(frmObj.Controls, "tblDynamicGrid");
        HiddenField hih;
        string strCtrlType;

        for (int j = 0; j <= controlarr.GetUpperBound(0); j++)
        {
            hih = new HiddenField();

            if (bln_update == false)
            {
                hih = (HiddenField)DDI.FindControl(frmObj.Controls, currentpage + controlarr[j, 1].ToString() + intRowCnt);
            }
            else
            {
                hih = (HiddenField)DDI.FindControl(frmObj.Controls, currentpage + controlarr[j, 1].ToString() + RowCnt);
            }

            strCtrlType = controlarr[j, 0].ToString();
            Label lbl;
            switch (strCtrlType.ToUpper())
            {
                case "DA":
                    break;
                case "DT":
                    break;
                case "TB":
                    TextBox txt = (TextBox)DDI.FindControl(frmObj.Controls, controlarr[j, 1].ToString());
                    hih.Value = txt.Text;

                    if (j == 0)
                    //if (j == 1) // srivatsan for caption renaming
                    {
                        lbl = (Label)DDI.FindControl(frmObj.Controls, currentpage + "lbl_control" + RowCnt);
                        lbl.Text = HttpUtility.HtmlEncode(txt.Text); // Encoded by 'Imran Gani' on 27-Dec-12
                    }
                    if (controlarr[j, 1].ToString() == "txt_size")
                    {
                        lbl = (Label)DDI.FindControl(frmObj.Controls, currentpage + "lbl_size" + RowCnt);
                        lbl.Text = txt.Text;

                    }
                    txt.Text = "";
                    break;
                case "CB":
                    CheckBox cb = (CheckBox)DDI.FindControl(frmObj.Controls, controlarr[j, 1].ToString());
                    hih.Value = cb.Checked.ToString();
                    cb.Checked = false;
                    break;
                case "DD":
                    DropDownList dd = (DropDownList)DDI.FindControl(frmObj.Controls, controlarr[j, 1].ToString());
                    if (controlarr[j, 1].ToString() == "dd_section_name")
                    { /****Modified By Dhanapal on 1 Dec 2010***/
                        //hih.Value = "Dfault TExt";
                        HtmlInputText htlTxt = (HtmlInputText)DDI.FindControl(frmObj.Controls, "Tags");
                        hih.Value = htlTxt.Value;
                    }
                    else
                    {
                        hih.Value = dd.SelectedValue;
                    }
                    if (controlarr[j, 1].ToString() == "dd_typeobject")
                    {
                        lbl = (Label)DDI.FindControl(frmObj.Controls, currentpage + "lbl_objecttype" + RowCnt);
                        lbl.Text = dd.SelectedValue;
                    }
                    if (controlarr[j, 1].ToString() == "dd_datatype")
                    {
                        lbl = (Label)DDI.FindControl(frmObj.Controls, currentpage + "lbl_datatype" + RowCnt);
                        lbl.Text = dd.SelectedValue;
                    }
                    /* if (controlarr[j, 1].ToString() == "dd_section_name") //Dhanapal For Section Name
                     {
                         lbl = (Label)DDI.FindControl(frmObj.Controls, currentpage + "lbl_section_name" + RowCnt);
                         //lbl.Text = dd.SelectedValue; //Dhanapal For Section Name
                         lbl.Text = "Test Value";

                     }*/
                    break;
                case "TA": // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
                    TextBox txt_area = (TextBox)DDI.FindControl(frmObj.Controls, controlarr[j, 1].ToString());
                    hih.Value = txt_area.Text;
                    break;
            }
        }
    }

    //protected void imgbtn_save_Click(object sender, ImageClickEventArgs e)
    //{
    //    LoadHiddenControls(false);
    //    GetDataset(); 
    //}

    //protected void imgbtn_update_Click(object sender, ImageClickEventArgs e)
    //{
    //    LoadHiddenControls(true);
    //    GetDataset(); 
    //}

    protected void pagewizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {
        FinishPage();
    }

    protected void pagewizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        HDD = new HDDatabase();
        string isexits;

        if (e.NextStepIndex == 1)
        {
            if ((IsCopy == true) || (IsEdit == false))
            {
                txtpsid.Text = GenerateID(txtpsname.Text);
                ps_id.Value = GenerateID(txtpsid.Text);
                pg_id.Value = "p_" + GenerateID(txtpsid.Text);
                obj_id.Value = "ob_" + GenerateID(txtpsid.Text);
                obj_bu_id.Value = "bu_" + GenerateID(txtpsid.Text); //Dont Change it By Dhanapal_Jan_11_2011
                //obj_bu_id.Value = "sy_" + GenerateID(txtpsid.Text);
                isexits = HDD.GetColumnValue("sy_pgs", "pageset_id", "pageset_id = '" + GenerateID(txtpsname.Text).Replace("'", "''") + "'");
                if (isexits.Trim().Length > 0)
                {
                    lbl_pageid.Text = "Page already exists! ";
                    e.Cancel = true;
                }
                else
                {
                    LoadWizard(false);
                }
            }
            else
            {
                LoadWizard(false);
            }
        }
        if (e.NextStepIndex == 2)
        {
            string message = "";
            if (validateDataType(ref message))
            {
                //LoadWizardMasterFields();
            }
            else
            {
                //lbl_message2.Text = "&nbsp;<img src='Images/error.gif' border='0'>&nbsp;" + (IsEdit == true ? "Updation" : "Insertion") + " not successful. " + lbl_message2.Text;
                lblMessage.Text = wrapItAsMessage("&nbsp;<img src='Images/error.gif' border='0'>&nbsp;" + (IsEdit == true ? "Updation" : "Insertion") + " not successful. <br />" + message, true);
                e.Cancel = true;
            }
        }
        if (e.NextStepIndex == 3)
        {
            LoadWizardPageEvents();
            GetPageChildRows();
        }
        if (e.NextStepIndex == 4) //Added By Dhanapal On Dec 21 2010
        {

        }
    }
    private bool validateDataType(ref string message)
    {
        bool returnFlag = true;
        if (Session["dseObjectInputInfo"] != null)
        {
            if (((DataSet)Session["dseObjectInputInfo"]).Tables["p_dobj_att"] != null)
            {
                DataTable dtControls = ((DataSet)Session["dseObjectInputInfo"]).Tables["p_dobj_att"];
                foreach (DataRow dr in dtControls.Rows)
                {
                    int size;
                    if (int.TryParse(dr["attrib_size"].ToString().Trim(), out size) == false)
                        size = 0;
                    if ((dr["attrib_data_type"].Equals("TX")) && (size > 4000))
                    {
                        //lbl_message2.Text = "The size (" + dr["attrib_size"].ToString() + ") given to the control '" + dr["attrib_name"].ToString() + "' exceeds the maximum allowed(4000).";
                        message = "The size (" + dr["attrib_size"].ToString() + ") given to the control '" + dr["attrib_name"].ToString() + "' exceeds the maximum allowed(4000).";
                        returnFlag = false;
                        break;
                    }
                }
            }
        }
        return returnFlag;
    }


    private void LoadTable(DataTable dtData, string strpage)
    {
        DataColumn dtcObj;
        DataRow droPageData;

        dtData.TableName = strpage;

        for (int j = 0; j <= controlarr.GetUpperBound(0); j++)
        {
            dtcObj = new DataColumn();
            dtcObj.ColumnName = controlarr[j, 1].ToString();
            dtData.Columns.Add(dtcObj);
        }

        foreach (DataRow drobjatt in dseObjectInputInfo.Tables["p_dobj_att"].Select("object_id = '" + obj_rowkey.Value + "'"))
        {
            droPageData = dtData.NewRow();
            foreach (DataRow drobj in dsePageInputInfo.Tables["p_pg_ctr"].Select("page_id = '" + pg_rowkey.Value + "' and control_attrib_id='" + drobjatt["attrib_id"] + "'"))
            {
                droPageData["txt_control_id"] = drobj["control_id"];
                droPageData["txt_control_name"] = drobj["control_name"];

                droPageData["ctr_af_row_id"] = drobj["af_row_id"];
                droPageData["att_af_row_id"] = drobjatt["af_row_id"];

                droPageData["ctr_owner_id"] = drobj["owner_id"]; // Added By 'Imran Gani' on 23-Jul-2013, For owner of a page control
                droPageData["att_owner_id"] = drobjatt["owner_id"]; // Added By 'Imran Gani' on 23-Jul-2013, For owner of a page control

                droPageData["dd_databind"] = drobj["control_bind_id"];

                droPageData["dd_inputmask"] = drobj["input_mask_format"];
                droPageData["cb_is_section"] = drobj["is_section"];//ssks
                droPageData["dd_section_name"] = drobj["section_name"];//Dhanapal For Section Name on Dec 1 2010
                droPageData["cb_is_search"] = drobj["is_search"];//ssks
                droPageData["cb_visible"] = drobj["control_visible"];
                droPageData["cb_readonly"] = drobj["read_only"];

                DataRow[] drps = dsePagesetInputInfo.Tables["p_pgs_srh"].Select("search_attrib_id = '" + drobjatt["attrib_id"] + "'");

                if (drps.Length > 0)
                {
                    droPageData["cb_list"] = drps[0]["list_flag"].ToString();
                    droPageData["cb_filter"] = drps[0]["quick_search"].ToString();
                }
                else
                {
                    droPageData["cb_list"] = "False";
                    droPageData["cb_filter"] = "False";
                }

                droPageData["dd_typeobject"] = drobj["control_html"];
                droPageData["txt_desc"] = drobjatt["attrib_description"];
                droPageData["txt_seq"] = drobj["control_seq"];
                droPageData["dd_datatype"] = drobj["control_attrib_type"];
                droPageData["txt_size"] = drobjatt["attrib_size"];
                droPageData["txt_default"] = drobj["default_value"];
                droPageData["cb_unique"] = drobjatt["is_primary"];
                droPageData["txt_tooltip"] = drobjatt["object_tooltip"];
                droPageData["dd_field_type"] = drobjatt["field_type"]; // Added By 'Imran Gani' on 15-Jul-2013, For Extended field support
            }
            dtData.Rows.Add(droPageData);
        }
    }
    private void manipulateColumn(DataTable dtaData, string columnName)//ssks
    {
        if (!dtaData.Columns.Contains(columnName)) return;
        if (dtaData.Rows.Count < 1) return;
        foreach (DataRow dr in dtaData.Rows)
        {
            if (dr[columnName] == DBNull.Value)
                dr[columnName] = "False";
        }
    }
    private void LoadWizard(bool bln_addrow)  //The Rows with Hidden Values Were Added Here Only
    {
        HDD = new HDDatabase();
        string strSql = "";
        string strPageId = "p_pg_ctr";
        string strcolumns = "";
        DDI = new DynamicDisplayI();

        strSql = "select A.* from sy_pg_ctr A INNER JOIN sy_pg B on A.page_id = B.af_row_id where B.page_id = '" + strPageId + "' order by A.page_id,A.control_seq asc";
        DataTable dtaPageCtrl = HDD.GetDataTable(strSql);

        foreach (DataRow row in dtaPageCtrl.Rows)
        {
            strcolumns = strcolumns + row["control_attrib_id"].ToString() + ",";
        }
        strcolumns = strcolumns.Substring(0, strcolumns.Length - 1);

        HtmlTable htObj = (HtmlTable)DDI.FindControl(frmObj.Controls, "tblDynamicGrid");
        htObj.Controls.Clear();
        int l = 0;

        if (SelChildPage.Items.Count == 0)
        {
            SelChildPage.Items.Add(new ListItem(HttpUtility.HtmlEncode(txtpsname.Text), HttpUtility.HtmlEncode(txtpsid.Text)));
        }

        foreach (ListItem sel in SelChildPage.Items)
        {
            l = l + 1;
            if (frmObj.Page.Request.Form["_sys" + sel.Value + "_RowCount"] != null)
                intRowCnt = Convert.ToInt32(frmObj.Page.Request.Form["_sys" + sel.Value + "_RowCount"].ToString());
            else if (frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$_sys" + sel.Value + "_RowCount"] != null)
                intRowCnt = Convert.ToInt32(frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$_sys" + sel.Value + "_RowCount"].ToString());

            if (frmObj.Page.Request.Form["_sys" + sel.Value + "_DelCount"] != null)
                intDelCnt = Convert.ToInt32(frmObj.Page.Request.Form["_sys" + sel.Value + "_DelCount"].ToString());
            else if (frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$_sys" + sel.Value + "_DelCount"] != null)
                intDelCnt = Convert.ToInt32(frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$_sys" + sel.Value + "_DelCount"].ToString());

            if (bln_addrow == true)
                intDelCnt = 0;

            if (dseObjectInputInfo.Tables.Count > 0)
            {
                dtaData = new DataTable();
                LoadTable(dtaData, sel.Text);
                //LoadSectionNameDropDown(dtaData);
                loadControlDroplist(dtaData); // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
            }
            else
            {
                strSql = "Select Distinct H.af_row_id as att_af_row_id, H.owner_id as att_owner_id" + // Modified By 'Imran Gani' on 23-Jul-2013, For owner of a page control

                        ",(Select af_row_id from sy_pg_ctr where D.af_row_id =page_id and control_id = H.attrib_id) as ctr_af_row_id" +
                        ",(Select owner_id from sy_pg_ctr where D.af_row_id =page_id and control_id = H.attrib_id) as ctr_owner_id" + // Added By 'Imran Gani' on 23-Jul-2013, For owner of a page control
                        ", H.attrib_name as txt_control_name,H.attrib_id as txt_control_id,H.attrib_data_type as dd_datatype,H.field_type as dd_field_type,H.attrib_size as txt_size,H.attrib_description as txt_desc,H.object_tooltip as txt_tooltip,H.is_primary as cb_unique" + // Modified By 'Imran Gani' on 15-Jul-2013, For Extended field support

                        ",(Select control_bind_id from  sy_pg_ctr where D.af_row_id =page_id and control_id = H.attrib_id) as dd_databind" +
                        ",(Select input_mask_format from  sy_pg_ctr where D.af_row_id =page_id and control_id = H.attrib_id) as dd_inputmask" +
                        ",(Select control_html from  sy_pg_ctr where D.af_row_id =page_id and control_id = H.attrib_id) as dd_typeobject" +
                        ",(Select default_value from  sy_pg_ctr where D.af_row_id =page_id and control_id = H.attrib_id) as txt_default" +
                        ",(Select control_visible from  sy_pg_ctr where D.af_row_id =page_id and control_id = H.attrib_id) as cb_visible" +
                        ",(Select read_only from  sy_pg_ctr where D.af_row_id =page_id and control_id = H.attrib_id) as cb_readonly" +
                        ",(Select is_section from  sy_pg_ctr where D.af_row_id =page_id and control_id = H.attrib_id) as cb_is_section" +//ssks
                        ",(Select section_name from  sy_pg_ctr where D.af_row_id =page_id and control_id = H.attrib_id) as dd_section_name" +//Dhanapal For Section Name on Dec 1 2010
                        ",(Select is_search from  sy_pg_ctr where D.af_row_id =page_id and control_id = H.attrib_id) as cb_is_search" +//Dhanapal For Search On Dec 14 2010
                        ",(Select control_seq from  sy_pg_ctr where D.af_row_id =page_id and control_id = H.attrib_id) as txt_seq" +

                        ",isnull((Select (case When len(page_id) > 0 then list_flag else 'false' end) " +
                        " from  sy_pgs_srh where D.page_id=page_id and H.attrib_id = search_attrib_id " +
                        " and A.af_row_id = pageset_id),'False') as [cb_list]" +

                        " ,isnull((Select (case When len(page_id) > 0 then quick_search else 'false' end) " +
                        " from  sy_pgs_srh where D.page_id=page_id and H.attrib_id = search_attrib_id " +
                        " and A.af_row_id = pageset_id),'False') as [cb_filter]" +

                        " from  sy_pgs A " +
                        " inner join  sy_pgs_mem B on A.af_row_id = B.pageset_id " +
                        " inner join  sy_pgs_srh C on A.af_row_id = C.pageset_id " +
                        " inner join  sy_pg D on D.page_id = B.page_id " +
                        " inner join  sy_pg_ctr E on D.af_row_id = E.page_id" +
                        " inner join  sy_obj G on G.object_id = D.object_id" +
                        " inner join  sy_obj_att H on G.af_row_id = H.object_id" +
                        " where A.pageset_id = '" + strPageKey.Replace("'", "''") + "' order by txt_seq";

                dtaData = HDD.GetDataTable(strSql);
                //function added by Sampath on 17-Nov-2011 for IPP Tech check 
                //CommonFunctions.decodeData(dtaData);
                manipulateColumn(dtaData, "cb_is_section");
                manipulateColumn(dtaData, "cb_is_search"); //Added By Dhanapal On Dec 14 2010 For Search
                dtaData.TableName = sel.Text;
                //LoadSectionNameDropDown(dtaData);
                dtaData.Columns.Add("ta_droplist"); // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
                loadControlDroplist(dtaData); // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
            }

            for (int g = dtaData.Rows.Count; g < intRowCnt; g++)
            {
                dtaData.Rows.Add(dtaData.NewRow());
            }

            foreach (DataColumn col in dtaData.Columns)
            {
                DataRow[] dr = dtaPageCtrl.Select("control_attrib_id='" + col.ColumnName + "'");
                if (dr.Length > 0)
                {
                    col.ColumnName = dr[0]["control_name"].ToString();
                    col.ExtendedProperties.Add("BindID", dr[0]["control_bind_id"].ToString());
                }
            }



            HtmlTable tblgrdDynamic = new HtmlTable();
            tblgrdDynamic.ID = "tbl_" + sel.Value;

            hdfDynamicGridId.Value = tblgrdDynamic.ID;//Hidden Field Contains the id of the Table by Dhanapal For Section Name on Dec 1 2010


            tblgrdDynamic.EnableViewState = false;
            tblgrdDynamic.Width = "100%";
            HtmlTableCell htcObj;
            HtmlTableRow htrObj;
            int i = 1;
            TextBox txtObj = new TextBox();

            tblgrdDynamic.CellPadding = 0;
            tblgrdDynamic.CellSpacing = 0;

            htrObj = new HtmlTableRow();

            htcObj = new HtmlTableCell();
            htcObj.InnerText = "Control Name";
            htrObj.Controls.Add(htcObj);
            htcObj = new HtmlTableCell();
            htcObj.InnerText = "Control Type";
            htrObj.Controls.Add(htcObj);
            htcObj = new HtmlTableCell();
            htcObj.InnerText = "Data Type";
            htrObj.Controls.Add(htcObj);

            htcObj = new HtmlTableCell();
            htcObj.InnerText = "Size";
            htrObj.Controls.Add(htcObj);

            /*htcObj = new HtmlTableCell();
            htcObj.InnerText = "Section Name";  //Dhanapal
            htrObj.Controls.Add(htcObj);*/

            htcObj = new HtmlTableCell();  //Dhanapal
            htcObj.InnerText = " ";
            htcObj.Width = "25px";
            htrObj.Controls.Add(htcObj);


            htcObj = new HtmlTableCell();
            htcObj.InnerText = " ";
            htcObj.Width = "25px";
            htrObj.Controls.Add(htcObj);

            htcObj = new HtmlTableCell();
            htcObj.InnerText = " ";
            htcObj.Width = "25px";
            htrObj.Controls.Add(htcObj);

            htrObj.Attributes.Add("Class", "Grid_Header");

            tblgrdDynamic.Controls.Add(htrObj);

            int j = 1;

            int visble_cnt = 0;
            foreach (DataRow row in dtaData.Rows)  // This Row Contains the values of all the controls
            {
                htrObj = new HtmlTableRow();
                htcObj = new HtmlTableCell();

                if ((intDelCnt == j) && intDelCnt.ToString().Length > 0)
                {
                }
                else
                {
                    int intRow = (tblgrdDynamic.Rows.Count + 1 + visble_cnt) % 2;
                    visble_cnt = 0;
                    HtmlTableRow htr = GetRowWizard(dtaData, dtaPageCtrl, sel.Value, i, row, false);
                    if (htr.Visible == false)
                        visble_cnt = 1;
                    htr.VAlign = "middle";
                    htr.Height = "20";
                    htr.ID = "tblgrdDynamictr_" + i; //Added By Dhanapal For Identifying the Row Count Client Side. on Dec 1 2010
                    htr.Attributes.Add("Class", "Grid_Row" + intRow.ToString());
                    htr.Attributes.Add("onMouseOver", "this.className='Grid_Scroll_BG'");
                    htr.Attributes.Add("onMouseOut", "this.className='" + "Grid_Row" + intRow.ToString() + "'");
                    tblgrdDynamic.Rows.Add(htr);
                    i = i + 1;
                }
                j = j + 1;
            }

            HtmlTableRow tblrow = new HtmlTableRow();
            HtmlTableCell tblcell = new HtmlTableCell();
            HtmlTable ht_header = new HtmlTable();

            tblrow.ID = "hd_" + sel.Text;
            TextBox tbltxt;
            CheckBox tblcb;
            Label tbllbl;
            Image hibtn;
            HtmlInputHidden hih;
            string cbvalue;

            hibtn = new Image();
            hibtn.ID = "AddRow" + sel.Value;
            hibtn.ImageUrl = "Images/AddRecord.gif";
            hibtn.ToolTip = "Add Control";
            hibtn.Attributes.Add("onclick", "AddRowValue('" + sel.Value + "','" + l + "')");
            tblcell.Controls.Add(hibtn);
            tblcell.VAlign = "middle";

            tblrow.Controls.Add(tblcell);

            tblcell = new HtmlTableCell();
            Label lk_btn = new Label();
            lk_btn.Text = @"<a href='#'>Add Control</a>";
            lk_btn.CssClass = "defaultFont";
            lk_btn.Font.Size = FontUnit.Point(8);
            lk_btn.Attributes.Add("onclick", "AddRowValue('" + sel.Value + "','" + l + "'); return false;");
            tblcell.Controls.Add(lk_btn);
            tblcell.VAlign = "middle";

            tblrow.Controls.Add(tblcell);

            tblrow.Align = "left";
            tblrow.VAlign = "middle";
            ht_header.Controls.Add(tblrow);

            tblrow = new HtmlTableRow();
            tblcell = new HtmlTableCell();

            tblcell.ColSpan = 2;
            tbllbl = new Label();
            tbllbl.ID = "Lbl_Name_" + sel.Value;
            tbllbl.Text = "  Page name ";
            //tbllbl.Font.Name = "Arial";  
            //tbllbl.Font.Size = FontUnit.Point(8);
            tbllbl.CssClass = "controlLabelFont";
            tblcell.Controls.Add(tbllbl);

            tbltxt = new TextBox();
            tbltxt.ID = "pg_name" + sel.Value;
            tbltxt.Text = txtpsname.Text;
            //tbltxt.Font.Name = "Arial";
            tbltxt.Enabled = false;
            //tbltxt.Font.Size = FontUnit.Point(8);
            tbltxt.CssClass = "controlFont";
            tblcell.Controls.Add(tbltxt);

            tbllbl = new Label();
            tbllbl.ID = "Lbl_No_Con_" + sel.Value;
            tbllbl.Text = " Controls per row ";
            //tbllbl.Font.Name = "Arial";
            //tbllbl.Font.Size = FontUnit.Point(8);
            tbllbl.CssClass = "controlLabelFont";
            tblcell.Controls.Add(tbllbl);

            tbltxt = new TextBox();
            tbltxt.ID = "Txt_No_Con_" + sel.Value;
            tbltxt.ToolTip = "Controls per each row";
            if (dsePageInputInfo.Tables.Count > 0)
            {
                tbltxt.Text = dsePageInputInfo.Tables["p_pg"].Rows[0]["control_per_row"].ToString();
            }
            else
            {
                tbltxt.Text = HDD.GetColumnValue("sy_pg", "control_per_row", "page_id = '" + sel.Value + "'");
            }

            //tbltxt.Font.Size = FontUnit.Point(8);
            tbltxt.CssClass = "controlFont";
            tblcell.Controls.Add(tbltxt);

            tblcb = new CheckBox();
            tblcb.ID = "dis_con_" + sel.Value;
            tblcb.Text = " Captions for 1st row only ";
            tblcb.ToolTip = "Captions for 1st row only";
            // tblcb.Font.Name = "Arial";
            if (dsePageInputInfo.Tables.Count > 0)
            {
                cbvalue = dsePageInputInfo.Tables["p_pg"].Rows[0]["first_row_caption_only"].ToString();
            }
            else
            {
                cbvalue = HDD.GetColumnValue("sy_pg", "first_row_caption_only", "page_id = '" + sel.Value + "'");
            }

            if (cbvalue.Length > 0)
            {
                tblcb.Checked = bool.Parse(cbvalue);
            }
            else
            {
                tblcb.Checked = false;
            }
            //tblcb.Font.Size = FontUnit.Point(8);
            tblcb.CssClass = "controlLabelFont";
            tblcell.Controls.Add(tblcb);

            tblcb = new CheckBox();
            tblcb.ID = "mul_rec" + sel.Value;
            tblcb.Text = " Multiple record page ";
            tblcb.ToolTip = "Multiple record page";
            //tblcb.Font.Name = "Arial";
            if (dsePageInputInfo.Tables.Count > 0)
            {

                cbvalue = dsePageInputInfo.Tables["p_pg"].Rows[0]["multiple_recs_page"].ToString();
            }
            else
            {
                cbvalue = HDD.GetColumnValue("sy_pg", "multiple_recs_page", "page_id = '" + sel.Value + "'");
            }
            if (cbvalue.Length > 0)
            {
                tblcb.Checked = bool.Parse(cbvalue);
            }
            else
            {
                tblcb.Checked = false;
            }
            //tblcb.Font.Size = FontUnit.Point(8);
            tblcb.CssClass = "controlLabelFont";
            tblcell.Controls.Add(tblcb);

            hih = new HtmlInputHidden();
            hih.ID = "rowcount_" + sel.Value;
            hih.Name = "rowcount_" + sel.Value;
            hih.Attributes.Add("runat", "server");

            if (frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$rowcount_" + sel.Value] != null)
            {
                hih.Value = frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$rowcount_" + sel.Value].ToString();
            }
            tblcell.Controls.Add(hih);

            hih = new HtmlInputHidden();
            hih.ID = "delcount_" + sel.Value;
            hih.Name = "delcount_" + sel.Value;
            hih.Attributes.Add("runat", "server");

            if (frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$delcount_" + sel.Value] != null)
            {
                hih.Value = frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$delcount_" + sel.Value].ToString();
            }
            tblcell.Controls.Add(hih);

            hih = new HtmlInputHidden();
            hih.ID = "updatecount_" + sel.Value;
            hih.Name = "updatecount_" + sel.Value;
            hih.Attributes.Add("runat", "server");
            tblcell.Controls.Add(hih);

            if (DDI.FindControl(frmObj.Controls, "_sys" + sel.Value + "_RowCount") == null)
            {
                int irow = dtaData.Rows.Count;
                HtmlInputHidden hihObj = new HtmlInputHidden();
                hihObj.ID = "_sys" + sel.Value + "_RowCount";
                hihObj.Value = irow.ToString();
                tblcell.Controls.Add(hihObj);
            }
            tblrow.Controls.Add(tblcell);

            if (DDI.FindControl(frmObj.Controls, "_sys" + sel.Value + "_DelCount") == null)
            {
                HtmlInputHidden hihObj = new HtmlInputHidden();
                hihObj.ID = "_sys" + sel.Value + "_DelCount";
                hihObj.Value = "0";
                tblcell.Controls.Add(hihObj);
            }

            tblrow.Controls.Add(tblcell);

            htrObj = new HtmlTableRow();
            htcObj = new HtmlTableCell();
            htcObj.Controls.Add(ht_header);
            htrObj.Controls.Add(htcObj);
            htObj.Controls.Add(htrObj);

            htrObj = new HtmlTableRow();
            htcObj = new HtmlTableCell();
            htcObj.Controls.Add(tblgrdDynamic);
            htrObj.Controls.Add(htcObj);

            htObj.Controls.Add(tblrow);
            htObj.Controls.Add(htrObj);

            HtmlInputHidden hihobj = (HtmlInputHidden)DDI.FindControl(frmObj.Controls, "_sys" + sel.Value + "_DelCount");
            hihobj.Value = "0";
        }

        GetDataset();
        GlobalValues.loadwizard = true;
    }

    private void LoadWizardMasterFields()
    {
        HDD = new HDDatabase();
        string strSql = "";

        string strPageId = "p_dobj_mas_detail";
        string strcolumns = "";
        DDI = new DynamicDisplayI();

        strSql = "select A.* from sy_pg_ctr A INNER JOIN sy_pg B on A.page_id = B.af_row_id where B.page_id = '" + strPageId.Replace("'", "''") + "' order by A.page_id, A.control_seq asc";
        DataTable dtaPageCtrl = HDD.GetDataTable(strSql);

        foreach (DataRow row in dtaPageCtrl.Rows)
        {
            strcolumns = strcolumns + "sy_obj_mas_detail." + row["control_attrib_id"].ToString() + ",";
        }
        strcolumns = strcolumns.Substring(0, strcolumns.Length - 1);

        HtmlTable htObj = (HtmlTable)DDI.FindControl(frmObj.Controls, "tblDynamicChild");
        htObj.Controls.Clear();

        foreach (ListItem sel in SelChildPage.Items)
        {
            if (frmObj.Page.Request.Form["_sys" + sel.Value + "_ChildRowCount"] != null)
                intChildRowCnt = Convert.ToInt32(frmObj.Page.Request.Form["_sys" + sel.Value + "_ChildRowCount"].ToString());
            else if (frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$_sys" + sel.Value + "_ChildRowCount"] != null)
                intChildRowCnt = Convert.ToInt32(frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$_sys" + sel.Value + "_ChildRowCount"].ToString());

            if (frmObj.Page.Request.Form["_sys" + sel.Value + "_ChildDelCount"] != null)
                intChildDelCnt = Convert.ToInt32(frmObj.Page.Request.Form["_sys" + sel.Value + "_ChildDelCount"].ToString());
            else if (frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$_sys" + sel.Value + "_ChildDelCount"] != null)
                intChildDelCnt = Convert.ToInt32(frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$_sys" + sel.Value + "_ChildDelCount"].ToString());

            if (GlobalValues.loadchildwizard == true)
            {
                dtaData = new DataTable();
                dtaData = dseObjectInputInfo.Tables[strPageId].Clone();
                DataRow[] dr = dseObjectInputInfo.Tables[strPageId].Select();
                for (int j = 0; j < dr.Length; j++)
                {
                    dtaData.ImportRow(dr[j]);
                }
            }
            else
            {
                strSql = "select " + strcolumns + ",sy_pg_ctr.af_row_id as pg_af_row_id from sy_obj_mas_detail inner join sy_obj on sy_obj_mas_detail.object_id= sy_obj.af_row_id inner join sy_pg on sy_pg.object_id = sy_obj.object_id inner join sy_pg_ctr on sy_pg_ctr.page_id= sy_pg.af_row_id and sy_obj_mas_detail.attrib_id = sy_pg_ctr.control_id " +
                         " where sy_pg.page_id = '" + sel.Value.Replace("'", "''") + "'";
                dtaData = HDD.GetDataTable(strSql);
                dtaData.TableName = sel.Text;
            }

            for (int g = dtaData.Rows.Count; g < intChildRowCnt; g++)
            {
                dtaData.Rows.Add(dtaData.NewRow());
            }

            foreach (DataColumn col in dtaData.Columns)
            {
                DataRow[] dr = dtaPageCtrl.Select("control_attrib_id='" + col.ColumnName + "'");
                if (dr.Length > 0)
                {
                    col.ColumnName = dr[0]["control_name"].ToString();
                    col.ExtendedProperties.Add("BindID", dr[0]["control_bind_id"].ToString());
                }
            }

            HtmlTable tblgrdDynamic = new HtmlTable();
            tblgrdDynamic.ID = "tbl_child" + sel.Value;
            tblgrdDynamic.EnableViewState = false;
            tblgrdDynamic.Width = "100%";
            HtmlTableCell htcObj;
            HtmlTableRow htrObj;
            int i = 1;
            TextBox txtObj = new TextBox();

            htrObj = new HtmlTableRow();
            htcObj = new HtmlTableCell();
            foreach (DataColumn col in dtaData.Columns)
            {
                Label hdlbl = new Label();
                hdlbl.ID = "Lbl_Child_" + sel.Value + "_" + col.ColumnName;
                hdlbl.Text = col.ColumnName.Trim();
                //hdlbl.Font.Size = FontUnit.Point(8);
                //hdlbl.Font.Name = "Arial";
                hdlbl.CssClass = "controlLabelfont";
                //hdlbl.Height = Unit.Pixel(10);

                if ((col.ColumnName.ToLower() == "page id") || (col.ColumnName.ToLower() == "pg_af_row_id") || (col.ColumnName.ToLower() == "af row id") || (col.ColumnName.ToLower() == "object id") || (col.ColumnName.ToLower() == "modified by") || (col.ColumnName.ToLower() == "modified at") || (col.ColumnName.ToLower() == "created by") || (col.ColumnName.ToLower() == "owner") || (col.ColumnName.ToLower() == "created at"))
                {
                    hdlbl.Visible = false;
                }

                htcObj = new HtmlTableCell();
                //htcObj.VAlign = "Bottom";
                //htcObj.VAlign = "Top";
                htcObj.NoWrap = true;
                htcObj.Controls.Add(hdlbl);


                htrObj.Controls.Add(htcObj);
                htrObj.VAlign = "Top";
            }

            tblgrdDynamic.Rows.Add(htrObj);

            if (GlobalValues.loadchildwizard != false)
            {
                if ((dtaData.Rows.Count > intChildRowCnt) && (intChildDelCnt != 0))
                {
                    dtaData.Rows.RemoveAt(intChildDelCnt - 1);
                    dtaData.AcceptChanges();
                }
            }

            if (dtaData.Rows.Count == 0)
                dtaData.Rows.Add(dtaData.NewRow());

            foreach (DataRow row in dtaData.Rows)
            {
                htrObj = new HtmlTableRow();
                htcObj = new HtmlTableCell();
                tblgrdDynamic.Rows.Add(GetRow(dtaData, dtaPageCtrl, sel.Value, i, row, false));
                i = i + 1;
            }

            HtmlTable ht_header = new HtmlTable();
            HtmlTableRow tblrow = new HtmlTableRow();
            HtmlTableCell tblcell = new HtmlTableCell();
            tblrow.ID = "hd_child" + sel.Text;
            Label tbllbl;
            TextBox tbltxt;
            ImageButton tblbtn;

            tblbtn = new ImageButton();
            tblbtn.ID = "child_" + sel.Value;
            tblbtn.ImageUrl = "Images/AddRecord.gif";
            tblbtn.ToolTip = "Add Master Control";
            tblbtn.Font.Size = FontUnit.Point(8);
            tblbtn.OnClientClick = "javascript:AddChildRowValue('" + sel.Value + "');";
            tblbtn.Click += new ImageClickEventHandler(tblbtn_Click);
            tblcell.Controls.Add(tblbtn);
            tblrow.Controls.Add(tblcell);

            tblcell = new HtmlTableCell();
            LinkButton lk_btn = new LinkButton();
            lk_btn.Text = "Add Master Control";
            lk_btn.CssClass = "defaultFont";
            lk_btn.Font.Size = FontUnit.Point(8);
            lk_btn.Attributes.Add("onclick", "AddChildRowValue('" + sel.Value + "');");
            lk_btn.Click += new EventHandler(lk_btn_Click);
            tblcell.Controls.Add(lk_btn);
            tblcell.VAlign = "middle";
            tblrow.Controls.Add(tblcell);
            tblrow.Align = "left";
            tblrow.VAlign = "middle";
            ht_header.Controls.Add(tblrow);

            tblrow = new HtmlTableRow();
            tblcell = new HtmlTableCell();
            tbllbl = new Label();
            tbllbl.ID = "Lbl_Name_Child" + sel.Value;
            tbllbl.Text = " Page name ";
            //tbllbl.Font.Size = FontUnit.Point(8);
            //tbllbl.Font.Name = "Arial";
            tbllbl.CssClass = "controlLabelFont";
            tblcell.Controls.Add(tbllbl);

            tbltxt = new TextBox();
            tbltxt.ID = "pg_name_child" + sel.Value;
            tbltxt.Text = txtpsname.Text;
            //tbltxt.Font.Name = "Arial";
            tbltxt.Enabled = false;
            //tbltxt.Font.Size = FontUnit.Point(8);
            tbltxt.CssClass = "controlFont";
            tblcell.Controls.Add(tbltxt);


            if (DDI.FindControl(frmObj.Controls, "_sys" + sel.Value + "_ChildRowCount") == null)
            {
                HtmlInputHidden hihObj = new HtmlInputHidden();
                hihObj.ID = "_sys" + sel.Value + "_ChildRowCount";
                hihObj.Value = dtaData.Rows.Count.ToString();
                tblcell.Controls.Add(hihObj);
            }
            tblrow.Controls.Add(tblcell);

            if (DDI.FindControl(frmObj.Controls, "_sys" + sel.Value + "_ChildDelCount") == null)
            {
                HtmlInputHidden hihObj = new HtmlInputHidden();
                hihObj.ID = "_sys" + sel.Value + "_ChildDelCount";
                hihObj.Value = "0";
                tblcell.Controls.Add(hihObj);
            }

            tblrow.Controls.Add(tblcell);

            ht_header.Border = 0;
            tblgrdDynamic.Border = 0;

            ht_header.CellPadding = 4;
            ht_header.CellSpacing = 0;

            tblgrdDynamic.CellSpacing = 0;
            tblgrdDynamic.CellPadding = 0;

            htrObj = new HtmlTableRow();
            htcObj = new HtmlTableCell();
            htcObj.Controls.Add(ht_header);
            htrObj.Controls.Add(htcObj);
            htObj.Controls.Add(htrObj);


            htrObj = new HtmlTableRow();
            htcObj = new HtmlTableCell();
            htcObj.Controls.Add(tblgrdDynamic);
            htrObj.Controls.Add(htcObj);

            htObj.Controls.Add(tblrow);
            htObj.Controls.Add(htrObj);
        }

        GetPageChildRows();
        GlobalValues.loadchildwizard = true;
    }

    void lk_btn_Click(object sender, EventArgs e)
    {
        if (GlobalValues.loadeventwizard == true)
        {
            GetPageEventRows();
        }
    }


    private void LoadWizardPageModeValues()
    {  
        HDD = new HDDatabase();
        string strsql = "";
        DataTable dt = new DataTable();
        strsql = "select spm.af_row_id , spm.mode , spmf.field ,spmf.field_type,spmf.af_row_id as modefieldsrowid from sy_pgs_mode spm inner join sy_pgs_mode_fields spmf on spm.af_row_id = spmf.mode_id where spm.pageset_id = '" + ps_rowkey.Value + "' and spm.mode = 'TV'";
        dt = HDD.GetDataTable(strsql);
        if (dt.Rows.Count > 0)
        {
            DataRow[] drnode = dt.Select("mode = 'TV'");
            if (drnode.Length > 0)
            {
                chkModeValue.Checked = true;
                foreach (DataRow dr in drnode)
                {
                    if (dr["field_type"].ToString() == "PARENT_NODE")
                    {
                        hdnParentField.Value = dr["modefieldsrowid"].ToString();
                        if (dr["field"].ToString() != "")
                            //ddlParentField.SelectedValue = dr["field"].ToString();
                            hdnParentFieldValue.Value = dr["field"].ToString(); ddlParentField.Enabled = true;

                    }
                    else if (dr["field_type"].ToString() == "CHILD_NODE")
                    {
                        hdnChildField.Value = dr["modefieldsrowid"].ToString();
                        if (dr["field"].ToString() != "")
                            // ddlChildField.SelectedValue = dr["field"].ToString();
                            hdnChildFieldValue.Value = dr["field"].ToString(); ddlChildField.Enabled = true;

                    }

                }
                
            }
           
            
        }
        /*else
        {
            disableTreeandCategoryview("ALL");
        }*/
        strsql = "select spm.af_row_id , spm.mode , spmf.field ,spmf.field_type,spmf.af_row_id as modefieldsrowid from sy_pgs_mode spm inner join sy_pgs_mode_fields spmf on spm.af_row_id = spmf.mode_id where spm.pageset_id = '" + ps_rowkey.Value + "' and spm.mode = 'CV'";
        dt = HDD.GetDataTable(strsql);
        if (dt.Rows.Count > 0)
        {
            DataRow[] Categoryfield = dt.Select("mode = 'CV'");
            if (Categoryfield.Length > 0)
            {
                chkCategoryValue.Checked = true;
                foreach (DataRow dr in Categoryfield)
                {
                    if (dr["field_type"].ToString() == "GROUPING") //Grouping Field
                    {
                        hdnCategoryFieldValue.Value = dr["field"].ToString(); ddlCategoryField.Enabled = true;
                    }
                }

            }
        }
        // Added by 'Imran Gani' (copied from RakaTech) on 27-May-2014, for Datasheet
        strsql = "select spm.af_row_id , spm.mode  from sy_pgs_mode spm where spm.pageset_id = '" + ps_rowkey.Value + "' and spm.mode = 'DS'";
        dt = HDD.GetDataTable(strsql);
        if (dt.Rows.Count > 0)
        {
            DataRow[] datasheetfield = dt.Select("mode = 'DS'");
            if (datasheetfield.Length > 0)
                ChkDatasheet.Checked = true;
        }
    }

    private void disableTreeandCategoryview(string key)//Added By Dhanapal on DEC272010
    {
        switch (key.ToString())
        {
            case "ALL":
                ddlParentField.Enabled = false;
                ddlChildField.Enabled = false;
                chkModeValue.Checked = false;
                chkCategoryValue.Checked = false;
                ddlCategoryField.Enabled = false;
                chkModeValue.Attributes.Add("onclick", "javascript:EnableModeDropdown(this);");
                chkCategoryValue.Attributes.Add("onclick", "javascript:EnableCategoryDropdown(this);");
                break;
            default:
                break;
        }
       
    }



    private void LoadWizardPageModes()//Added By Dhanapal on DEC232010
    {
        txtPageName.Text = txtpsname.Text.ToString();
        string strParentSelectedField = "";
        string strChildSelectedField = "";
        string strCategorySelectedField = ""; //Added By Dhanapal on Jan 20 2011

        if (GlobalValues.loadpagemodewizard == false)
        {
            strParentSelectedField = hdnParentFieldValue.Value;
            strChildSelectedField = hdnChildFieldValue.Value;
            strCategorySelectedField = hdnCategoryFieldValue.Value; //Added By Dhanapal on Jan 20 2011
        }
        else
        {
            strParentSelectedField = ddlParentField.SelectedValue;
            strChildSelectedField = ddlChildField.SelectedValue;
            strCategorySelectedField = ddlCategoryField.SelectedValue; //Added By Dhanapal on Jan 20 2011
        }

        /*if (ddlParentField.SelectedValue.ToString() != "")
             strParentSelectedField = ddlParentField.SelectedValue;
        else
             strParentSelectedField = hdnParentFieldValue.Value;

        if (ddlChildField.SelectedValue.ToString() != "")
             strChildSelectedField = ddlChildField.SelectedValue;
        else
             strChildSelectedField = hdnChildFieldValue.Value;*/

        ddlParentField.Items.Clear();
        ddlChildField.Items.Clear();
        ddlCategoryField.Items.Clear(); //Added By Dhanapal on Jan 20 2011

        foreach (DataRow dr1 in dsePageInputInfo.Tables["p_pg_ctr"].Rows)
        {
            if (checkInArrayList(false, dr1["control_id"].ToString().ToLower()) == false)
            {
                //ddlParentField.Items.Add(new ListItem(dr1["control_id"].ToString(), "[" + obj_id.Value + "].[" + dr1["control_id"].ToString() + "]"));
                //ddlChildField.Items.Add(new ListItem(dr1["control_id"].ToString(), "[" + obj_id.Value + "].[" + dr1["control_id"].ToString() + "]"));
                ddlParentField.Items.Add(new ListItem(dr1["control_id"].ToString(), dr1["control_id"].ToString()));
                ddlChildField.Items.Add(new ListItem(dr1["control_id"].ToString(), dr1["control_id"].ToString()));
                ddlCategoryField.Items.Add(new ListItem(dr1["control_id"].ToString(), dr1["control_id"].ToString())); //Added By Dhanapal on Jan 20 2011
            }
        }

        ddlParentField.Items.Insert(0, "");
        ddlChildField.Items.Insert(0, "");
        ddlCategoryField.Items.Insert(0, "");

        if (chkModeValue.Checked)
        {
            ddlParentField.Enabled = true;
            ddlChildField.Enabled = true;
        }
        else
        {
            ddlParentField.Enabled = false;
            ddlChildField.Enabled  = false;
        }


        if (chkCategoryValue.Checked) //Added By Dhanapal on Jan 20 2011
            ddlCategoryField.Enabled = true;
        else
            ddlCategoryField.Enabled = false; 
        
       if( ddlParentField.Items.FindByText(strParentSelectedField.ToString()) != null )
            ddlParentField.SelectedValue = strParentSelectedField.ToString();
       if( ddlChildField.Items.FindByText(strChildSelectedField.ToString())  != null )
            ddlChildField.SelectedValue = strChildSelectedField.ToString();
       if (ddlCategoryField.Items.FindByText(strCategorySelectedField.ToString()) != null)
            ddlCategoryField.SelectedValue = strCategorySelectedField.ToString();
        //LoadWizardPageModeValues();//Added By Dhanapal ON DEC272010

       GlobalValues.loadpagemodewizard = true;// Added By Dhanapal on DEC282010 to maintain whether the wizard loaded or not

    }

    private void LoadWizardPageEvents()
    {
        HDD = new HDDatabase();
        string strSql = "";

        string strPageId = "p_pg_evnt";
        string strcolumns = "";
        DDI = new DynamicDisplayI();

        strSql = "select A.* from sy_pg_ctr A INNER JOIN sy_pg B on A.page_id = B.af_row_id where B.page_id = '" + strPageId.Replace("'", "''") + "' order by A.page_id, A.control_seq asc";
        DataTable dtaPageCtrl = HDD.GetDataTable(strSql);

        foreach (DataRow row in dtaPageCtrl.Rows)
        {
            strcolumns = strcolumns + row["control_attrib_id"].ToString() + ",";
        }
        strcolumns = strcolumns.Substring(0, strcolumns.Length - 1);

        HtmlTable htObj = (HtmlTable)DDI.FindControl(frmObj.Controls, "tblDynamicEvent");
        htObj.Controls.Clear();

        foreach (ListItem sel in SelChildPage.Items)
        {
            if (frmObj.Page.Request.Form["_sys" + sel.Value + "_EventRowCount"] != null)
                intEventRowCnt = Convert.ToInt32(frmObj.Page.Request.Form["_sys" + sel.Value + "_EventRowCount"].ToString());
            else if (frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$_sys" + sel.Value + "_EventRowCount"] != null)
                intEventRowCnt = Convert.ToInt32(frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$_sys" + sel.Value + "_EventRowCount"].ToString());

            if (frmObj.Page.Request.Form["_sys" + sel.Value + "_EventDelCount"] != null)
                intEventDelCnt = Convert.ToInt32(frmObj.Page.Request.Form["_sys" + sel.Value + "_EventDelCount"].ToString());
            else if (frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$_sys" + sel.Value + "_EventDelCount"] != null)
                intEventDelCnt = Convert.ToInt32(frmObj.Page.Request.Form["ctl00$ContentPlaceHolder3$pagewizard$_sys" + sel.Value + "_EventDelCount"].ToString());

            if (GlobalValues.loadeventwizard == true)
            {
                dtaData = new DataTable();
                dtaData = dsePageInputInfo.Tables[strPageId].Clone();
                DataRow[] dr = dsePageInputInfo.Tables[strPageId].Select();
                for (int j = 0; j < dr.Length; j++)
                {
                    dtaData.ImportRow(dr[j]);
                }
            }
            else
            {
                strSql = "select " + strcolumns + " from sy_pg_evnt where page_id in ( " +
                         " Select af_row_id from sy_pg where page_id = '" + sel.Value.Replace("'", "''") + "')";
                dtaData = HDD.GetDataTable(strSql);
                dtaData.TableName = sel.Text;
            }

            for (int g = dtaData.Rows.Count; g < intEventRowCnt; g++)
            {
                dtaData.Rows.Add(dtaData.NewRow());
            }

            foreach (DataColumn col in dtaData.Columns)
            {
                DataRow[] dr = dtaPageCtrl.Select("control_attrib_id='" + col.ColumnName + "'");
                if (dr.Length > 0)
                {
                    col.ColumnName = dr[0]["control_name"].ToString();
                    col.ExtendedProperties.Add("BindID", dr[0]["control_bind_id"].ToString());
                }
            }

            HtmlTable tblgrdDynamic = new HtmlTable();
            tblgrdDynamic.ID = "tbl_event" + sel.Value;
            tblgrdDynamic.EnableViewState = false;
            tblgrdDynamic.Width = "100%";
            HtmlTableCell htcObj;
            HtmlTableRow htrObj;
            int i = 1;
            TextBox txtObj = new TextBox();

            htrObj = new HtmlTableRow();
            htcObj = new HtmlTableCell();
            foreach (DataColumn col in dtaData.Columns)
            {
                Label hdlbl = new Label();
                hdlbl.ID = "Lbl_Event_" + sel.Value + "_" + col.ColumnName;
                hdlbl.Text = col.ColumnName.Trim();
                //hdlbl.Font.Size = FontUnit.Point(8);
                //hdlbl.Font.Name = "Arial";

                hdlbl.CssClass = "controlLabelfont";
                //hdlbl.Height = Unit.Pixel(10);

                if ((col.ColumnName.ToLower() == "page id") || (col.ColumnName.ToLower() == "created by") || (col.ColumnName.ToLower() == "owner") || (col.ColumnName.ToLower() == "created date") || (col.ColumnName.ToLower() == "af row id") || (col.ColumnName.ToLower() == "modified date") || (col.ColumnName.ToLower() == "modified by")) // Modified by srivatsan for Owner_id Changes
                {
                    hdlbl.Visible = false;
                }

                htcObj = new HtmlTableCell();
                htcObj.VAlign = "Bottom";
                htcObj.NoWrap = true;
                htcObj.Controls.Add(hdlbl);
                htrObj.Controls.Add(htcObj);
            }
            htcObj = new HtmlTableCell();
            Literal lt = new Literal();
            lt.Text = "&nbsp;";
            htcObj.Controls.Add(lt);
            htrObj.Controls.Add(htcObj);
            tblgrdDynamic.Rows.Add(htrObj);

            if (GlobalValues.loadeventwizard != false)
            {
                if ((dtaData.Rows.Count > intEventRowCnt) && (intEventDelCnt != 0))
                {
                    dtaData.Rows.RemoveAt(intEventDelCnt - 1);
                    dtaData.AcceptChanges();
                }
            }

            if (dtaData.Rows.Count == 0)
                dtaData.Rows.Add(dtaData.NewRow());

            foreach (DataRow row in dtaData.Rows)
            {
                tblgrdDynamic.Rows.Add(GetRow(dtaData, dtaPageCtrl, sel.Value, i, row, true));
                i = i + 1;
            }

            HtmlTable ht_header = new HtmlTable();
            HtmlTableRow tblrow = new HtmlTableRow();
            HtmlTableCell tblcell = new HtmlTableCell();
            tblrow.ID = "hd_event" + sel.Text;
            Label tbllbl;
            TextBox tbltxt;
            ImageButton tblbtn;
            tblbtn = new ImageButton();
            tblbtn.ID = "event_" + sel.Value;
            tblbtn.ToolTip = "Add Event";
            tblbtn.ImageUrl = "Images/AddRecord.gif";
            tblbtn.Font.Size = FontUnit.Point(8);
            tblbtn.OnClientClick = "javascript:AddEventRowValue('" + sel.Value + "');";
            tblbtn.Click += new ImageClickEventHandler(tblbtn_Click);
            tblcell.Controls.Add(tblbtn);
            tblrow.Controls.Add(tblcell);

            tblcell = new HtmlTableCell();
            LinkButton lk_btn = new LinkButton();
            lk_btn.Text = "Add Event";
            lk_btn.CssClass = "defaultFont";
            lk_btn.Font.Size = FontUnit.Point(8);
            lk_btn.Attributes.Add("onclick", "AddEventRowValue('" + sel.Value + "');");
            lk_btn.Click += new EventHandler(lk_btn_Click);
            tblcell.Controls.Add(lk_btn);
            tblcell.VAlign = "middle";
            tblrow.Controls.Add(tblcell);
            tblrow.Align = "left";
            tblrow.VAlign = "middle";

            ht_header.Controls.Add(tblrow);

            tblrow = new HtmlTableRow();
            tblcell = new HtmlTableCell();

            tbllbl = new Label();
            tbllbl.ID = "Lbl_Name_Event" + sel.Value;
            tbllbl.Text = " Page name ";
            //tbllbl.Font.Name = "Arial"; 
            //tbllbl.Font.Size = FontUnit.Point(8);
            tbllbl.CssClass = "controlLabelfont";
            tblcell.Controls.Add(tbllbl);

            tbltxt = new TextBox();
            tbltxt.ID = "pg_name_event" + sel.Value;
            tbltxt.Text = txtpsname.Text;
            tbltxt.CssClass = "defaultFont";
            tbltxt.Enabled = false;
            tbltxt.Font.Size = FontUnit.Point(8);
            tblcell.Controls.Add(tbltxt);

            if (DDI.FindControl(frmObj.Controls, "_sys" + sel.Value + "_EventRowCount") == null)
            {
                HtmlInputHidden hihObj = new HtmlInputHidden();
                hihObj.ID = "_sys" + sel.Value + "_EventRowCount";
                hihObj.Value = dtaData.Rows.Count.ToString();
                tblcell.Controls.Add(hihObj);
            }
            tblrow.Controls.Add(tblcell);

            if (DDI.FindControl(frmObj.Controls, "_sys" + sel.Value + "_EventDelCount") == null)
            {
                HtmlInputHidden hihObj = new HtmlInputHidden();
                hihObj.ID = "_sys" + sel.Value + "_EventDelCount";
                hihObj.Value = "0";
                tblcell.Controls.Add(hihObj);
            }

            tblrow.Controls.Add(tblcell);
            htrObj = new HtmlTableRow();
            htcObj = new HtmlTableCell();

            ht_header.Border = 0;
            tblgrdDynamic.Border = 0;

            ht_header.CellPadding = 0;
            ht_header.CellSpacing = 0;
            tblgrdDynamic.CellSpacing = 0;
            tblgrdDynamic.CellPadding = 0;


            htcObj.Controls.Add(ht_header);
            htrObj.Controls.Add(htcObj);
            htObj.Controls.Add(htrObj);

            htrObj = new HtmlTableRow();
            htcObj = new HtmlTableCell();
            htcObj.Align = "left";
            htcObj.Controls.Add(tblgrdDynamic);
            htrObj.Controls.Add(htcObj);

            htObj.Controls.Add(tblrow);
            htObj.Controls.Add(htrObj);
        }
        GetPageEventRows();
        GlobalValues.loadeventwizard = true;
    }

    private HtmlTableRow GetRow(DataTable dtaData, DataTable dtaPageCtrl, string selvalue, int i, DataRow row, bool bln_pageevent)
    {
        HtmlTableCell htcObj;
        HtmlTableRow htrObj;

        DataRow droPageData;

        HDD = new HDDatabase();
        string strSql = "";
        string eventfunctype = "";

        string con_id = "";
        string strCtrlType = "";
        string strBindRowID = "";
        string strpgevent = "";
        TextBox txtObj = new TextBox();
        ScreenReader SR = new ScreenReader();

        htrObj = new HtmlTableRow();
        htcObj = new HtmlTableCell();
        DataRow[] droCtrData;
        htrObj.Align = "left";
        droCtrData = dtaPageCtrl.Select("control_id = 'af_row_id'");

        droPageData = dtaPageCtrl.NewRow();

        foreach (DataColumn dc in dtaPageCtrl.Columns)
        {
            droPageData[dc] = droCtrData[0][dc.ColumnName];
        }
        dtaPageCtrl.Rows.Add(droPageData);

        dtaPageCtrl.Rows[dtaPageCtrl.Rows.Count - 1]["control_id"] = "pg_af_row_id";
        dtaPageCtrl.Rows[dtaPageCtrl.Rows.Count - 1]["control_name"] = "pg_af_row_id";
        dtaPageCtrl.Rows[dtaPageCtrl.Rows.Count - 1]["control_attrib_id"] = "pg_af_row_id";

        foreach (DataColumn col in dtaData.Columns)
        {
            DataRow[] dr = dtaPageCtrl.Select("control_Name='" + col.ColumnName + "'");

            if (dr.Length > 0)
            {
                if (bln_pageevent == true)
                {
                    con_id = selvalue + "_event_" + dr[0]["control_attrib_id"].ToString() + "_" + i;
                }
                else
                {
                    if (col.ColumnName == "pg_af_row_id")
                    {
                        con_id = selvalue + "_child_" + dr[0]["control_attrib_id"].ToString() + "_" + i;
                    }
                    else
                    {
                        con_id = selvalue + "_child_" + dr[0]["control_attrib_id"].ToString() + "_" + i;
                    }
                }

                strCtrlType = dr[0]["control_html"].ToString();
                strBindRowID = dr[0]["control_bind_id"].ToString();

                switch (strCtrlType.ToUpper())
                {
                    case "DA":
                    case "DT":
                    case "TB":
                        txtObj = new TextBox();
                        txtObj.ID = con_id;
                        txtObj.EnableViewState = true;
                        //txtObj.Font.Size = FontUnit.Point(8);
                        //txtObj.Font.Name = "Arial";
                        txtObj.CssClass = "controlFont";
                        if (row[col.ColumnName].ToString() != "")
                            txtObj.Text = row[col.ColumnName].ToString();

                        if ((dr[0]["control_attrib_id"].ToString() == "control_seq") || (dr[0]["control_attrib_id"].ToString() == "event_sequence"))
                        {
                            txtObj.Width = 50;
                        }
                        else
                        {
                            txtObj.Width = 80;
                        }
                        if ((dr[0]["control_attrib_id"].ToString().ToLower() == "af_row_id") || (dr[0]["control_attrib_id"].ToString().ToLower() == "pg_af_row_id"))
                        {
                            if (dtaData.Rows.Count == 1)
                            {
                                if (txtObj.Text.Trim() == "")
                                    txtObj.Text = SR.getHashKey();
                            }
                            else
                            {
                                txtObj.Text = row[col.ColumnName].ToString();
                            }
                            txtObj.Visible = false;
                        }

                        if (checkInArrayList(false, dr[0]["control_attrib_id"].ToString().ToLower()))
                        {
                            txtObj.Visible = false;
                        }

                        if (dr[0]["control_attrib_id"].ToString().ToLower() == "object_id")
                        {
                            //ddlObj.DataSource = HDD.GetDataTable("Select af_row_id as Value,object_id as Field from sy_obj order by object_id");
                            //ddlObj.DataTextField = "Field";
                            //ddlObj.DataValueField = "Value";
                            //ddlObj.DataBind();
                            //ddlObj.Items.Add("");
                            txtObj.Visible = false;
                            txtObj.Text = obj_rowkey.Value;
                        }

                        if ((dr[0]["control_attrib_id"].ToString().ToLower() == "page_id"))
                        {
                            txtObj.Visible = false;
                            txtObj.Text = selvalue;
                        }

                        htcObj = new HtmlTableCell();
                        htcObj.Controls.Add(txtObj);
                        htrObj.Controls.Add(htcObj);
                        break;
                    case "CB":
                        CheckBox cbObj = new CheckBox();
                        cbObj.ID = con_id;
                        if (row[col.ColumnName].ToString() != "")
                        {
                            cbObj.Checked = bool.Parse(row[col.ColumnName].ToString());
                        }
                        htcObj = new HtmlTableCell();
                        htcObj.Controls.Add(cbObj);
                        htrObj.Controls.Add(htcObj);
                        break;
                    case "DD":
                        string bindid = "";
                        string bindtable = "";
                        string bind_value = "";
                        string bind_text = "";

                        strSql = "";
                        DropDownList ddlObj = new DropDownList();
                        if (strBindRowID.Trim() != "")
                        {

                            if (!(dr[0]["control_attrib_id"].ToString().ToLower() == "display_att"))
                            {
                                bindtable = HDD.GetColumnValue("sy_bnd", "bind_table", "af_row_id = '" + strBindRowID + "'");
                                bindid = HDD.GetColumnValue("sy_bnd", "bind_parameter", "af_row_id = '" + strBindRowID + "'");
                                bind_value = HDD.GetColumnValue("sy_bnd", "bind_value", "af_row_id = '" + strBindRowID + "'");
                                bind_text = HDD.GetColumnValue("sy_bnd", "bind_text", "af_row_id = '" + strBindRowID + "'");

                                strSql = "Select " + bind_text + " as Field ," + bind_value + " as Value from " + bindtable;

                                if (bindid != "")
                                {
                                    strSql = strSql + " where " + bindid;
                                }

                                strSql = strSql + " order by " + bind_text;


                                if (checkInArrayList(false, dr[0]["control_attrib_id"].ToString().ToLower())) // Added by srivatsan on June 15 2009 for owner id field
                                {
                                    ddlObj.Visible = false;
                                }

                                if (dr[0]["control_attrib_id"].ToString().ToLower() == "master_obj")
                                {
                                    strSql = applysecurity(strSql);
                                }

                                ddlObj.DataSource = HDD.GetDataTable(strSql);
                                ddlObj.DataTextField = "Field";
                                ddlObj.DataValueField = "Value";
                                ddlObj.DataBind();
                                ddlObj.Items.Add("");
                            }
                            if (row[col.ColumnName].ToString() != "")
                            {
                                ddlObj.SelectedValue = row[col.ColumnName].ToString();
                            }
                            else
                            {
                                ddlObj.SelectedValue = "";
                            }

                            if ((dr[0]["control_attrib_id"].ToString().ToLower() == "page_id"))
                            {
                                ddlObj.Visible = false;
                                ddlObj.SelectedValue = selvalue;
                            }

                            if (dr[0]["control_attrib_id"].ToString().ToLower() == "page_event")
                            {
                                ddlObj.AutoPostBack = true;
                                ddlObj.SelectedIndexChanged += new EventHandler(ddlObj_SelectedIndexChanged);
                                ddlObj.SkinID = selvalue;
                                strpgevent = ddlObj.SelectedValue;
                            }
                        }

                        if (bln_pageevent == false)
                        {
                            if (dr[0]["control_attrib_id"].ToString().ToLower() == "object_id")
                            {
                                ddlObj.DataSource = HDD.GetDataTable("Select af_row_id as Value,object_id as Field from sy_obj order by object_id");
                                ddlObj.DataTextField = "Field";
                                ddlObj.DataValueField = "Value";
                                ddlObj.DataBind();
                                ddlObj.Items.Add("");
                                ddlObj.Visible = false;
                                ddlObj.SelectedValue = obj_rowkey.Value;
                            }
                        }

                        if (dr[0]["control_attrib_id"].ToString().ToLower() == "master_obj")
                        {
                            ddlObj.AutoPostBack = true;
                            ddlObj.SelectedIndexChanged += new EventHandler(ddlchildObj_SelectedIndexChanged);
                            ddlObj.SkinID = selvalue;
                        }

                        if (dr[0]["control_attrib_id"].ToString().ToLower() == "display_att")
                        {
                            DataTable dsd = HDD.GetDataTable("Select A.attrib_name as var_name ,A.attrib_id as var_id from sy_obj_att A inner join sy_obj B on A.object_id = B.af_row_id" +
                                           " where B.object_id = '" + row["Master Object"].ToString().Replace("'", "''") + "' order by A.attrib_id");
                            foreach (DataRow dr2 in dsd.Rows)
                                if (checkInArrayList(false, dr2["var_id"].ToString().ToLower()) == false)
                                    ddlObj.Items.Add(new ListItem(dr2["var_name"].ToString(), dr2["var_id"].ToString()));
                            dsd = null;

                            ddlObj.SelectedValue = row[col.ColumnName].ToString();
                        }


                        if (dr[0]["control_attrib_id"].ToString().ToLower() == "event_type")
                        {
                            ddlObj.AutoPostBack = true;
                            ddlObj.SelectedIndexChanged += new EventHandler(ddlObj_SelectedIndexChanged);
                            ddlObj.SkinID = selvalue;

                            eventfunctype = ddlObj.SelectedValue.ToLower();

                            if (strpgevent.ToLower() == "pl")
                            {
                                ddlObj.Items.Remove(ddlObj.Items.FindByValue("v"));
                            }
                            else
                            {
                                if ((strpgevent.ToLower() == "pas") || (strpgevent.ToLower() == "pau"))
                                {
                                    ddlObj.Items.Remove(ddlObj.Items.FindByValue("av"));
                                }
                                ddlObj.Enabled = true;
                            }
                        }

                        if (dr[0]["control_attrib_id"].ToString().ToLower() == "event_function")
                        {
                            ddlObj.AutoPostBack = true;
                            DataTable dt_FN = new DataTable();
                            if (eventfunctype == "a")
                            {
                                dt_FN = HDD.GetDataTable("Select distinct fr_name as FN_Name,id as FN_id from my_function_register");
                            }
                            else if (eventfunctype == "av")
                            {
                                ddlObj.DataTextField = "FN_Name";
                                ddlObj.DataValueField = "FN_id";

                                foreach (DataRow dr1 in dsePageInputInfo.Tables["p_pg_ctr"].Rows)
                                {
                                    if (checkInArrayList(false, dr1["control_id"].ToString().ToLower()) == false)
                                        ddlObj.Items.Add(new ListItem(dr1["control_id"].ToString(), "[" + obj_id.Value + "." + dr1["control_id"].ToString() + "]"));
                                }

                                dt_FN = HDD.GetDataTable("Select distinct sy_var_name as FN_Name,sy_var_name as FN_id from sy_var");
                                foreach (DataRow dr1 in dt_FN.Rows)
                                    ddlObj.Items.Add(new ListItem("{!" + dr1["FN_Name"].ToString() + "}", "{!" + dr1["FN_id"].ToString() + "}"));
                                dt_FN = null;

                                dt_FN = HDD.GetDataTable("Select distinct mem_name as FN_Name,mem_id as FN_id from sy_acr_mem where acr_id = 'e9dc3cad2428a694'");
                                foreach (DataRow dr1 in dt_FN.Rows)
                                    ddlObj.Items.Add(new ListItem(dr1["FN_Name"].ToString(), dr1["FN_id"].ToString()));
                                dt_FN = null;
                            }
                            else if (eventfunctype == "v")
                            {
                                dt_FN = HDD.GetDataTable("Select fr_name as FN_Name,id as FN_id from my_function_register where fr_isValidation = 1 and ft_type='Function'");
                            }
                            else if (eventfunctype == "ad")
                            {
                                dt_FN = HDD.GetDataTable("Select function_name as FN_Name,af_row_id as FN_id from sy_page_events_advanced");
                            }

                            if (eventfunctype != "av")
                            {
                                ddlObj.DataTextField = "FN_Name";
                                ddlObj.DataValueField = "FN_id";

                                foreach (DataRow dr1 in dt_FN.Rows)
                                    ddlObj.Items.Add(new ListItem(dr1["FN_Name"].ToString(), dr1["FN_id"].ToString()));
                                dt_FN = null;
                            }

                            ddlObj.Enabled = true;
                            if (row[col.ColumnName].ToString().Length > 0)
                                ddlObj.SelectedValue = row[col.ColumnName].ToString();
                        }
                        ddlObj.Width = 150;
                        if (dr[0]["control_attrib_id"].ToString().ToLower() == "event_ass_cont")
                        {
                            if (eventfunctype == "v" || eventfunctype == "ad")
                            {
                                ddlObj.Items.Clear();
                                ddlObj.Enabled = false;
                            }
                            else
                            {
                                foreach (DataRow dr1 in dsePageInputInfo.Tables["p_pg_ctr"].Rows)
                                {
                                    if (checkInArrayList(false, dr1["control_id"].ToString().ToLower()) == false)
                                        ddlObj.Items.Add(new ListItem(dr1["control_id"].ToString(), "[" + obj_id.Value + "].[" + dr1["control_id"].ToString() + "]"));
                                }

                                ddlObj.SelectedValue = row[col.ColumnName].ToString();
                                ddlObj.Enabled = true;
                            }
                            ddlObj.Width = 250;
                        }

                        ddlObj.ID = con_id;

                        //ddlObj.Font.Size = FontUnit.Point(8);
                        //ddlObj.Font.Name = "Arial";
                        ddlObj.CssClass = "controlFont";

                        htcObj = new HtmlTableCell();
                        htcObj.Controls.Add(ddlObj);
                        htrObj.Controls.Add(htcObj);
                        break;
                }
            }
            else
            {
                CheckBox cbObj = new CheckBox();

                if (bln_pageevent == true)
                {
                    con_id = selvalue + "_event_" + col.ColumnName + "_" + i;
                }
                else
                {
                    con_id = selvalue + "_child_" + col.ColumnName + "_" + i;
                }
                cbObj.ID = con_id;
                if (row[col.ColumnName].ToString() != "")
                    cbObj.Checked = bool.Parse(row[col.ColumnName].ToString());
                htcObj = new HtmlTableCell();
                htcObj.Controls.Add(cbObj);
                htrObj.Controls.Add(htcObj);
            }
        }

        ImageButton btnObj = new ImageButton();
        btnObj.Font.Size = FontUnit.Point(8);
        btnObj.ImageUrl = "images/delete.gif";
        btnObj.ToolTip = "Delete";
        if (bln_pageevent == true)
        {
            btnObj.ID = selvalue + "_Event" + i;
            btnObj.OnClientClick = "javascript:RemoveEventRow('" + selvalue + "','" + i + "');";
            btnObj.Click += new ImageClickEventHandler(tblremovebtn_Click);
        }
        else
        {
            btnObj.ID = selvalue + "_" + i;
            btnObj.OnClientClick = "javascript:RemoveChildRow('" + selvalue + "','" + i + "');";
            btnObj.Click += new ImageClickEventHandler(tblremovebtn_Click);
        }

        if (dtaData.Rows.Count == 1)
        {
            if (row[1].ToString().Length > 0)
            {
                btnObj.Visible = true;
            }
            else
            {
                btnObj.Visible = false;
            }
        }

        htcObj = new HtmlTableCell();
        htcObj.Controls.Add(btnObj);

        htrObj.Controls.Add(htcObj);
        return htrObj;
    }


    private HtmlTableRow GetRowWizard(DataTable dtaData, DataTable dtaPageCtrl, string selvalue, int i, DataRow row, bool bln_pageevent)
    {
        HtmlTableCell htcObj;
        HtmlTableRow htrObj;

        HDD = new HDDatabase();
        bool IsActionAllowed = true; // Added By 'Imran Gani' on 15-Jul-2013, For Extended field support

        htrObj = new HtmlTableRow();
        htcObj = new HtmlTableCell();
        ImageButton hibtn;
        ImageButton ibtn;
        Label lbl;
        HiddenField hih;

        lbl = new Label();
        lbl.ID = selvalue + "lbl_control" + i;
        htcObj.NoWrap = true;
        htcObj.Controls.Add(lbl);
        htrObj.Controls.Add(htcObj);

        htcObj = new HtmlTableCell();
        Label lbl1 = new Label();
        lbl1.ID = selvalue + "lbl_objecttype" + i;
        htcObj.Controls.Add(lbl1);
        htrObj.Controls.Add(htcObj);

        htcObj = new HtmlTableCell();
        Label lbl2 = new Label();
        lbl2.ID = selvalue + "lbl_datatype" + i;
        htcObj.Controls.Add(lbl2);
        htrObj.Controls.Add(htcObj);

        htcObj = new HtmlTableCell();
        Label lbl3 = new Label();
        lbl3.ID = selvalue + "lbl_size" + i;
        htcObj.Controls.Add(lbl3);
        htrObj.Controls.Add(htcObj);

        /*htcObj = new HtmlTableCell(); //Dhanapal For Section Name
        Label lbl4 = new Label();
        lbl4.ID = selvalue + "lbl_section_name" + i;
        htcObj.Controls.Add(lbl4);
        htrObj.Controls.Add(htcObj);*/

        htcObj = new HtmlTableCell();
        for (int j = 0; j <= controlarr.GetUpperBound(0); j++)
        {
            if (j == 0)
            //if (j == 1) // Srivatsan for caption renaming
            {
                lbl.Text = HttpUtility.HtmlEncode(row[controlarr[j, 1].ToString()].ToString());
                lbl.Width = 100;
            }
            if (controlarr[j, 1].ToString() == "dd_typeobject")
            {
                lbl1.Text = row[controlarr[j, 1].ToString()].ToString();
                lbl1.Width = 100;
            }
            if (controlarr[j, 1].ToString() == "dd_datatype")
            {
                lbl2.Text = row[controlarr[j, 1].ToString()].ToString();
                lbl2.Width = 100;
            }
            if (controlarr[j, 1].ToString() == "txt_size")
            {
                lbl3.Text = row[controlarr[j, 1].ToString()].ToString();
                lbl3.Width = 100;
            }
            if (controlarr[j, 1].ToString() == "dd_section_name") //Dhanapal
            {
                //String sec_name  = row[controlarr[j, 1].ToString()].ToString();
                //lbl4.Width = 100;
            }
            if (controlarr[j, 1].ToString() == "dd_field_type") // Added By 'Imran Gani' on 15-Jul-2013, For Extended field support
            {
                if (row[controlarr[j, 1].ToString()].ToString() != "" && row[controlarr[j, 1].ToString()].ToString() != "USR" && Session["user_afrowid"].ToString() != "e51e0327224a2eb9")
                    IsActionAllowed = false;
            }
            hih = new HiddenField();
            hih.ID = selvalue + controlarr[j, 1].ToString() + i;
            hih.Value = row[controlarr[j, 1].ToString()].ToString();
            if (checkInArrayList(true, row[controlarr[j, 1].ToString()].ToString().ToLower()))
                htrObj.Visible = false;
            htcObj.Controls.Add(hih);
        }
        htrObj.Controls.Add(htcObj);

        htcObj = new HtmlTableCell();
        if (IsActionAllowed) // Added By 'Imran Gani' on 15-Jul-2013, For Extended field support
        {
            //hibtn = new Image();
            hibtn = new ImageButton();
            hibtn.ID = "add" + selvalue + "_" + i;
            hibtn.ImageUrl = "images/edit_wizard.gif";
            hibtn.ToolTip = "Edit";
            hibtn.Attributes.Add("onclick", "EditRowValue('" + selvalue + "','" + i + "');return false;");
            htcObj.Width = "25px";
            htcObj.Controls.Add(hibtn);
        }
        htrObj.Controls.Add(htcObj);
        htcObj = new HtmlTableCell();
        if (IsActionAllowed) // Added By 'Imran Gani' on 15-Jul-2013, For Extended field support
        {
            ibtn = new ImageButton();
            ibtn.ID = "remove_" + selvalue + "_" + i;
            ibtn.ImageUrl = "images/delete.gif";
            ibtn.ToolTip = "Delete";
            ibtn.Attributes.Add("onclick", "RemoveRowValue('" + selvalue + "','" + i + "')");
            ibtn.Click += new ImageClickEventHandler(tblremovebtn_Click);
            htcObj.Width = "25px";
            htcObj.Controls.Add(ibtn);
        }
        htrObj.Controls.Add(htcObj);

        return htrObj;
    }

    void ddlchildObj_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = new DropDownList();
        ddl = (DropDownList)sender;
        DropDownList ddObj = (DropDownList)DDI.FindControl(frmObj.Controls, ddl.SkinID + "_child_display_att_" + ddl.ID.Substring(ddl.ID.LastIndexOf("_") + 1));
        ddObj.Items.Clear();
        DataTable dsd = HDD.GetDataTable("Select  A.attrib_name as var_name ,A.attrib_id as var_id from sy_obj_att A inner join sy_obj B on A.object_id = B.af_row_id" +
                                           " where B.object_id = '" + ddl.SelectedValue.Replace("'", "''") + "' order by A.attrib_name");
        foreach (DataRow dr in dsd.Rows)
            if (checkInArrayList(false, dr["var_id"].ToString().ToLower()) == false)
                ddObj.Items.Add(new ListItem(dr["var_name"].ToString(), dr["var_id"].ToString()));
        dsd = null;

        GetPageChildRows();
    }

    void ddlObj_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = new DropDownList();
        ddl = (DropDownList)sender;
        DropDownList ddObj = (DropDownList)DDI.FindControl(frmObj.Controls, ddl.SkinID + "_event_event_ass_cont_" + ddl.ID.Substring(ddl.ID.LastIndexOf("_") + 1));
        DropDownList dd1Obj = (DropDownList)DDI.FindControl(frmObj.Controls, ddl.SkinID + "_event_event_function_" + ddl.ID.Substring(ddl.ID.LastIndexOf("_") + 1));
        DropDownList dd2Obj = (DropDownList)DDI.FindControl(frmObj.Controls, ddl.SkinID + "_event_event_type_" + ddl.ID.Substring(ddl.ID.LastIndexOf("_") + 1));

        if (ddl.ID.IndexOf("page_event") > 0)
        {
            
            if (ddl.SelectedValue.ToLower() == "pl")
            {
                dd2Obj.SelectedValue = "a";
                //dd2Obj.Enabled = false;
                dd2Obj.Items.Remove(dd2Obj.Items.FindByValue("v"));
                ddObj.Enabled = true;
                ddObj.Items.Clear();
                foreach (DataRow dr in dsePageInputInfo.Tables["p_pg_ctr"].Rows)
                {
                    if (checkInArrayList(false, dr["control_id"].ToString().ToLower()) == false)
                        ddObj.Items.Add(new ListItem(dr["control_id"].ToString(), "[" + obj_id.Value + "].[" + dr["control_id"].ToString() + "]"));
                }

                dd1Obj.Items.Clear();
                DataTable ds = HDD.GetDataTable("Select distinct fr_name as FN_Name,id as FN_id from my_function_register");
                foreach (DataRow dr in ds.Rows)
                    dd1Obj.Items.Add(new ListItem(dr["FN_Name"].ToString(), dr["FN_id"].ToString()));
                ds = null;
                ddObj.Enabled = true;
            }
            else if (ddl.SelectedValue.ToLower() == "pad")//changes made by Bala to include after delete functionality 
            {
                dd1Obj.Items.Clear();
                DataTable ds = HDD.GetDataTable("Select function_name as FN_Name,af_row_id as FN_id from sy_page_events_advanced");
                foreach (DataRow dr in ds.Rows)
                    dd1Obj.Items.Add(new ListItem(dr["FN_Name"].ToString(), dr["FN_id"].ToString()));
                ds = null;
                ddObj.Items.Clear();
                ddObj.Enabled = false;
                dd2Obj.Items.Remove(dd2Obj.Items.FindByValue("av"));
                dd2Obj.Items.Remove(dd2Obj.Items.FindByValue("a"));
                dd2Obj.Items.Remove(dd2Obj.Items.FindByValue("v"));
            }

            else
            {
                if ((ddl.SelectedValue.ToLower() == "pas") || (ddl.SelectedValue.ToLower() == "pau"))
                {
                    dd2Obj.Items.Remove(dd2Obj.Items.FindByValue("av"));
                    dd2Obj.Items.Remove(dd2Obj.Items.FindByValue("a"));
                }

                dd2Obj.Enabled = true;
                if (dd2Obj.SelectedValue.ToLower() == "v")
                {
                    ddObj.Enabled = false;
                }
                else
                {
                    ddObj.Enabled = true;
                    ddObj.Items.Clear();
                    foreach (DataRow dr in dsePageInputInfo.Tables["p_pg_ctr"].Rows)
                    {
                        if (checkInArrayList(false, dr["control_id"].ToString().ToLower()) == false)
                            ddObj.Items.Add(new ListItem(dr["control_id"].ToString(), "[" + obj_id.Value + "].[" + dr["control_id"].ToString() + "]"));
                    }
                }

            }
        }
        else
        {
            if (ddl.SelectedValue.ToLower() == "a")
            {
                ddObj.Items.Clear();
                foreach (DataRow dr in dsePageInputInfo.Tables["p_pg_ctr"].Rows)
                {
                    if (checkInArrayList(false, dr["control_id"].ToString().ToLower()) == false)
                        ddObj.Items.Add(new ListItem(dr["control_id"].ToString(), "[" + obj_id.Value + "].[" + dr["control_id"].ToString() + "]"));
                }

                dd1Obj.Items.Clear();
                DataTable ds = HDD.GetDataTable("Select distinct fr_name as FN_Name,id as FN_id from my_function_register");
                foreach (DataRow dr in ds.Rows)
                    dd1Obj.Items.Add(new ListItem(dr["FN_Name"].ToString(), dr["FN_id"].ToString()));
                ds = null;
                ddObj.Enabled = true;
            }
            else if (ddl.SelectedValue.ToLower() == "av")
            {
                ddObj.Items.Clear();
                dd1Obj.Items.Clear();
                foreach (DataRow dr in dsePageInputInfo.Tables["p_pg_ctr"].Rows)
                {
                    if (checkInArrayList(false, dr["control_id"].ToString().ToLower()) == false)
                    {
                        ddObj.Items.Add(new ListItem(dr["control_id"].ToString(), "[" + obj_id.Value + "].[" + dr["control_id"].ToString() + "]"));
                        dd1Obj.Items.Add(new ListItem(dr["control_id"].ToString(), "[" + obj_id.Value + "].[" + dr["control_id"].ToString() + "]"));
                    }
                }
                DataTable ds = HDD.GetDataTable("Select distinct sy_var_name as FN_Name,sy_var_name as FN_id from sy_var");
                foreach (DataRow dr in ds.Rows)
                    dd1Obj.Items.Add(new ListItem("{!" + dr["FN_Name"].ToString() + "}", "{!" + dr["FN_id"].ToString() + "}"));
                ds = null;

                ds = HDD.GetDataTable("Select distinct mem_name as FN_Name,mem_id as FN_id from sy_acr_mem where acr_id = 'e9dc3cad2428a694'");
                foreach (DataRow dr in ds.Rows)
                    dd1Obj.Items.Add(new ListItem(dr["FN_Name"].ToString(), dr["FN_id"].ToString()));
                ds = null;

                ddObj.Enabled = true;
            }
            else if (ddl.SelectedValue.ToLower() == "v")
            {
                dd1Obj.Items.Clear();
                DataTable ds = HDD.GetDataTable("Select fr_name as FN_Name,id as FN_id from my_function_register where fr_isValidation = 1 and ft_type='Function'");
                foreach (DataRow dr in ds.Rows)
                    dd1Obj.Items.Add(new ListItem(dr["FN_Name"].ToString(), dr["FN_id"].ToString()));
                ds = null;
                ddObj.Enabled = false;
            }
            else if (ddl.SelectedValue.ToLower() == "ad")
            {
                dd1Obj.Items.Clear();
                DataTable ds = HDD.GetDataTable("Select function_name as FN_Name,af_row_id as FN_id from sy_page_events_advanced");
                foreach (DataRow dr in ds.Rows)
                    dd1Obj.Items.Add(new ListItem(dr["FN_Name"].ToString(), dr["FN_id"].ToString()));
                ds = null;
                ddObj.Items.Clear();
                ddObj.Enabled = false;
            }
            else
            {
                dd1Obj.Items.Clear();
                DataTable ds = HDD.GetDataTable("Select function_name as FN_Name,af_row_id as FN_id from sy_page_events_advanced");
                foreach (DataRow dr in ds.Rows)
                    dd1Obj.Items.Add(new ListItem(dr["FN_Name"].ToString(), dr["FN_id"].ToString()));
                ds = null;
                ddObj.Enabled = false;
            }
        }
        GetPageEventRows();
    }

    public bool GetPageEventRows()
    {
        bool blnStatus = true;
        DataRow droPageData;
        HDD = new HDDatabase();
        DDI = new DynamicDisplayI();

        strPagesetRowID = "91f98d67d57b9830"; // ps_pg_event
        string strPageId = "";

        ScreenReader SR = new ScreenReader();
        Master MA = new Master();

        PageInfoLoad PIL = new PageInfoLoad();
        dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowID);

        DataTable dtaPageSet = dsePageInfo.Tables["PageSet"];
        DataTable dtaPage = dsePageInfo.Tables["Page"];
        DataTable dtaPageKeys = dsePageInfo.Tables["PageKeys"];
        DataTable dtaPageCtrl = dsePageInfo.Tables["PageCtrl"];

        if (dsePageInputInfo.Tables.Contains(dtaPage.Rows[0]["page_id"].ToString()) == false)
        {
            SR.CreatePageDataTable(dsePageInputInfo, dtaPage, dtaPageCtrl);
        }

        for (int i = 0; i < dtaPage.Rows.Count; i++)
        {
            strPageId = dtaPage.Rows[i]["page_id"].ToString();

            if (strPageId == "p_pg")
            {
            }
            else if (strPageId == "p_pg_ctr")
            {
            }
            else if (strPageId == "p_pg_key")
            {
            }
            else if (strPageId == "p_pg_evnt")
            {
                dsePageInputInfo.Tables[strPageId].Clear();
                DataRow[] dr = dtaPageCtrl.Select("page_id='" + HDD.GetColumnValue("Select af_row_id from sy_pg where page_id = '" + strPageId.Replace("'", "''") + "'") + "'");
                foreach (ListItem sel in SelChildPage.Items)
                {
                    int s = 0;
                    HtmlTable hhtObj = (HtmlTable)DDI.FindControl(frmObj.Controls, "tbl_event" + sel.Value);

                    foreach (HtmlTableRow orow in hhtObj.Rows)
                    {
                        if (s < hhtObj.Rows.Count - 1)
                        {
                            s = s + 1;
                            droPageData = dsePageInputInfo.Tables[strPageId].NewRow();

                            for (int j = 0; j < dr.Length; j++)
                            {
                                string strCtrlType = dr[j]["control_html"].ToString();
                                switch (strCtrlType.ToUpper())
                                {
                                    case "DA":
                                    case "DT":
                                    case "TB":
                                        TextBox txtObj = (TextBox)DDI.FindControl(frmObj.Controls, sel.Value + "_event_" + dr[j]["control_attrib_id"].ToString() + "_" + s);
                                        if (txtObj != null)
                                        {
                                            if ((dr[j]["control_attrib_id"].ToString().ToLower() == "af_row_id"))
                                            {
                                                if (txtObj.Text.Trim() == "")
                                                {
                                                    droPageData[dr[j]["control_attrib_id"].ToString()] = SR.getHashKey();
                                                }
                                                else
                                                {
                                                    droPageData[dr[j]["control_attrib_id"].ToString()] = txtObj.Text;
                                                }
                                            }
                                            else if ((dr[j]["control_attrib_id"].ToString().ToLower() == "page_id"))
                                            {
                                                droPageData[dr[j]["control_attrib_id"].ToString()] = pg_rowkey.Value;
                                            }

                                            else
                                            {
                                                droPageData[dr[j]["control_attrib_id"].ToString()] = txtObj.Text;
                                            }
                                        }
                                        break;
                                    case "CB":
                                        CheckBox cbObj = (CheckBox)DDI.FindControl(frmObj.Controls, sel.Value + "_event_" + dr[j]["control_attrib_id"].ToString() + "_" + s);
                                        if (cbObj != null)
                                        {
                                            droPageData[dr[j]["control_attrib_id"].ToString()] = cbObj.Checked;
                                        }
                                        break;
                                    case "DD":
                                        DropDownList ddlObj = (DropDownList)DDI.FindControl(frmObj.Controls, sel.Value + "_event_" + dr[j]["control_attrib_id"].ToString() + "_" + s);

                                        if (ddlObj != null)
                                        {
                                            if ((dr[j]["control_attrib_id"].ToString().ToLower() == "page_id"))
                                            {
                                                droPageData[dr[j]["control_attrib_id"].ToString()] = pg_rowkey.Value;
                                            }
                                            else
                                            {
                                                droPageData[dr[j]["control_attrib_id"].ToString()] = ddlObj.SelectedValue;
                                            }
                                        }
                                        break;
                                }
                            }

                            if (droPageData["page_event"].ToString() != "")
                                dsePageInputInfo.Tables[strPageId].Rows.Add(droPageData);
                        }
                    }
                }
            }
        }
        Session["dsePageInputInfo"] = dsePageInputInfo;
        return blnStatus;
    }

    public bool GetPageChildRows()
    {
        bool blnStatus = true;

        DataRow droPageData;
        DataRow[] droCtrData;

        HDD = new HDDatabase();
        DDI = new DynamicDisplayI();

        strPagesetRowID = "e7dd8bdbcd9c6454"; // ps_dobj_mas_detail
        string strPageId = "";

        ScreenReader SR = new ScreenReader();
        Master MA = new Master();

        PageInfoLoad PIL = new PageInfoLoad();
        dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowID);

        DataTable dtaPageSet = dsePageInfo.Tables["PageSet"];
        DataTable dtaPage = dsePageInfo.Tables["Page"];
        DataTable dtaPageKeys = dsePageInfo.Tables["PageKeys"];
        DataTable dtaPageCtrl = dsePageInfo.Tables["PageCtrl"];

        droCtrData = dtaPageCtrl.Select("control_id = 'af_row_id'");

        droPageData = dtaPageCtrl.NewRow();

        foreach (DataColumn dc in dtaPageCtrl.Columns)
        {
            droPageData[dc] = droCtrData[0][dc.ColumnName];
        }
        dtaPageCtrl.Rows.Add(droPageData);

        dtaPageCtrl.Rows[dtaPageCtrl.Rows.Count - 1]["control_id"] = "pg_af_row_id";
        dtaPageCtrl.Rows[dtaPageCtrl.Rows.Count - 1]["control_attrib_id"] = "pg_af_row_id";


        if (dseObjectInputInfo.Tables.Contains(dtaPage.Rows[0]["page_id"].ToString()) == false)
        {
            SR.CreatePageDataTable(dseObjectInputInfo, dtaPage, dtaPageCtrl);
        }

        for (int i = 0; i < dtaPage.Rows.Count; i++)
        {
            strPageId = dtaPage.Rows[i]["page_id"].ToString();
            if (strPageId == "p_dobj_mas_detail")
            {
                dseObjectInputInfo.Tables[strPageId].Clear();
                DataRow[] dr = dtaPageCtrl.Select("page_id='" + HDD.GetColumnValue("Select af_row_id from sy_pg where page_id = '" + strPageId.Replace("'", "''") + "'") + "'");
                foreach (ListItem sel in SelChildPage.Items)
                {
                    int s = 0;
                    HtmlTable hhtObj = (HtmlTable)DDI.FindControl(frmObj.Controls, "tbl_child" + sel.Value);

                    foreach (HtmlTableRow orow in hhtObj.Rows)
                    {
                        if (s < hhtObj.Rows.Count - 1)
                        {
                            s = s + 1;
                            droPageData = dseObjectInputInfo.Tables[strPageId].NewRow();

                            for (int j = 0; j < dr.Length; j++)
                            {
                                string strCtrlType = dr[j]["control_html"].ToString();
                                switch (strCtrlType.ToUpper())
                                {
                                    case "DA":
                                    case "DT":
                                    case "TB":
                                        TextBox txtObj = (TextBox)DDI.FindControl(frmObj.Controls, sel.Value + "_child_" + dr[j]["control_attrib_id"].ToString() + "_" + s);
                                        if (txtObj != null)
                                        {
                                            if ((dr[j]["control_attrib_id"].ToString().ToLower() == "af_row_id") || (dr[j]["control_attrib_id"].ToString().ToLower() == "pg_af_row_id"))
                                            {
                                                if (txtObj.Text.Trim() == "")
                                                {
                                                    droPageData[dr[j]["control_attrib_id"].ToString()] = SR.getHashKey();
                                                }
                                                else
                                                {
                                                    droPageData[dr[j]["control_attrib_id"].ToString()] = txtObj.Text;
                                                }
                                            }
                                            else
                                            {
                                                droPageData[dr[j]["control_attrib_id"].ToString()] = txtObj.Text;
                                            }
                                        }
                                        break;
                                    case "CB":
                                        CheckBox cbObj = (CheckBox)DDI.FindControl(frmObj.Controls, sel.Value + "_child_" + dr[j]["control_attrib_id"].ToString() + "_" + s);
                                        if (cbObj != null)
                                        {
                                            droPageData[dr[j]["control_attrib_id"].ToString()] = cbObj.Checked;
                                        }
                                        break;
                                    case "DD":
                                        DropDownList ddlObj = (DropDownList)DDI.FindControl(frmObj.Controls, sel.Value + "_child_" + dr[j]["control_attrib_id"].ToString() + "_" + s);
                                        if (ddlObj != null)
                                        {
                                            if (dr[j]["control_attrib_id"].ToString().ToLower() == "object_id")
                                            {
                                                droPageData[dr[j]["control_attrib_id"].ToString()] = obj_rowkey.Value;
                                            }
                                            else
                                            {
                                                droPageData[dr[j]["control_attrib_id"].ToString()] = ddlObj.SelectedValue;
                                            }
                                        }
                                        break;
                                }
                            }

                            if (droPageData["attrib_id"].ToString() != "")
                                dseObjectInputInfo.Tables[strPageId].Rows.Add(droPageData);
                        }
                    }
                }
            }
        }
        Session["dseObjectInputInfo"] = dseObjectInputInfo;
        return blnStatus;
    }

    protected void pagewizard_PreviousButtonClick(object sender, WizardNavigationEventArgs e)
    {
        if (e.NextStepIndex == 0)
        {
            string message = "";
            if (!validateDataType(ref message))
            {
                lblMessage.Text = wrapItAsMessage("&nbsp;<img src='Images/error.gif' border='0'>&nbsp;" + (IsEdit == true ? "Updation" : "Insertion") + " not successful. <br />" + message,true);
                e.Cancel = true;
            }
        }
        else if (e.NextStepIndex == 1)
        {
            LoadWizard(false);
            GetPageChildRows();
        }
        else if (e.NextStepIndex == 2)
        {
            LoadWizardMasterFields();
            GetPageEventRows();
        }
        else if (e.NextStepIndex == 3) //Added By Dhanapal On Dec 21 2010
        {
            LoadWizardPageEvents();
            GetPageChildRows();
        }
    }

    protected void pagewizard_CancelButtonClick(object sender, EventArgs e)
    {
        HDDatabase HDD = new HDDatabase();

        dseObjectInputInfo = null;
        dsePageInputInfo = null;
        dsePagesetInputInfo = null;

        Session["dseObjectInputInfo"] = null;
        Session["dsePageInputInfo"] = null;
        Session["dsePagesetInputInfo"] = null;

        Response.Redirect("DisplayGrid.aspx?mn=" + HDD.GetColumnValue("sy_mnu", "af_row_id", "pageset_id = 'b3ef063b174e4ccc' and pageset_url = 'PageWizard.aspx'") + "&pgs_id=b3ef063b174e4ccc"); // pageset_id and pgs_id=ps_pageset
    }

    private bool GetDataset()
    {
        string[,] pagearr = pagearr = new string[,] 
            {
                {"Object", "9ec6aa32504a516b"}, // ps_dobj
                {"Object", "cdb0ecf826945479"}, // ps_dobj_att
                {"Object", "e7dd8bdbcd9c6454"}, // ps_dobj_mas_detail

                {"Page", "50f21749fc3da2ee"}, // ps_page
                {"Page", "534b6e11207db844"}, // ps_pg_ctr
                {"Page", "3b58ce68486728f4"}, // pg_ctr_droplist // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
                {"Page", "91f98d67d57b9830"}, // ps_pg_event
                {"Page", "b8a9ac90d9c3e9ba"}, // ps_pg_key
               

                {"Pageset", "b3ef063b174e4ccc"}, // ps_pageset
                {"Pageset", "a40f400c6424ef4e"}, // ps_pgs_mem
                {"Pageset", "be2f0230028f06a6"}, // ps_pgs_srh

                {"Pageset", "d0faefe8b944568b"}, // pgs_mode //Added By dhanapal ON DEC232010
                {"Pageset", "e3800174ff18ccb0"} // pgs_mode_fields

                
            };
        DDI = new DynamicDisplayI();
        string strPagesetRowID;
        bool Status = false;

        for (int j = 0; j <= pagearr.GetUpperBound(0); j++)
        {
            ScreenReader SR = new ScreenReader();
            Master MA = new Master();
            PageInfoLoad PIL = new PageInfoLoad();

            strPagesetRowID = pagearr[j, 1].ToString();
            dsePageInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowID);

            DataTable dtaPageSet = dsePageInfo.Tables["PageSet"];
            DataTable dtaPage = dsePageInfo.Tables["Page"];
            DataTable dtaPageKeys = dsePageInfo.Tables["PageKeys"];
            DataTable dtaPageCtrl = dsePageInfo.Tables["PageCtrl"];

            //if ((strPagesetRowID == "ps_dobj") || (strPagesetRowID == "ps_dobj_att"))
            if ((strPagesetRowID == "9ec6aa32504a516b") || (strPagesetRowID == "cdb0ecf826945479"))
            {
                if (dseObjectInputInfo.Tables.Contains(dtaPage.Rows[0]["page_id"].ToString()) == false)
                    SR.CreatePageDataTable(dseObjectInputInfo, dtaPage, dtaPageCtrl);
                GetDataset(dseObjectInputInfo, strPagesetRowID, dtaPage, dtaPageCtrl);
                Session["dseObjectInputInfo"] = dseObjectInputInfo;
            }
            //else if ((strPagesetRowID == "ps_page") || (strPagesetRowID == "ps_pg_ctr") || (strPagesetRowID == "ps_pg_key") || (strPagesetRowID == "pg_ctr_droplist")) // Modified by 'Imran Gani' on 26-Dec-2013, for droplist support.
            else if ((strPagesetRowID == "50f21749fc3da2ee") || (strPagesetRowID == "534b6e11207db844") || (strPagesetRowID == "b8a9ac90d9c3e9ba") || (strPagesetRowID == "3b58ce68486728f4")) // Modified by 'Imran Gani' on 26-Dec-2013, for droplist support.
            {
                if (dsePageInputInfo.Tables.Contains(dtaPage.Rows[0]["page_id"].ToString()) == false)
                    SR.CreatePageDataTable(dsePageInputInfo, dtaPage, dtaPageCtrl);
                GetDataset(dsePageInputInfo, strPagesetRowID, dtaPage, dtaPageCtrl);
                Session["dsePageInputInfo"] = dsePageInputInfo;
            }
            //else if ((strPagesetRowID == "ps_pageset") || (strPagesetRowID == "ps_pgs_mem") || (strPagesetRowID == "ps_pgs_srh"))
            else if ((strPagesetRowID == "b3ef063b174e4ccc") || (strPagesetRowID == "a40f400c6424ef4e") || (strPagesetRowID == "be2f0230028f06a6"))
            {
                if (dsePagesetInputInfo.Tables.Contains(dtaPage.Rows[0]["page_id"].ToString()) == false)
                    SR.CreatePageDataTable(dsePagesetInputInfo, dtaPage, dtaPageCtrl);
                GetDataset(dsePagesetInputInfo, strPagesetRowID, dtaPage, dtaPageCtrl);
                Session["dsePagesetInputInfo"] = dsePagesetInputInfo;
            }
            //else if ((strPagesetRowID == "pgs_mode") || (strPagesetRowID == "pgs_mode_fields")) //Added BY Dhanapal On DEC232010
            else if ((strPagesetRowID == "d0faefe8b944568b") || (strPagesetRowID == "e3800174ff18ccb0")) //Added BY Dhanapal On DEC232010
            {
                if (dsePagesetInputInfo.Tables.Contains(dtaPage.Rows[0]["page_id"].ToString()) == false)
                    SR.CreatePageDataTable(dsePagesetInputInfo, dtaPage, dtaPageCtrl);
                GetDataset(dsePagesetInputInfo, strPagesetRowID, dtaPage, dtaPageCtrl);
                Session["dsePagesetInputInfo"] = dsePagesetInputInfo;
            }
        }
        return Status;
    }

    private string GenerateID(string strid)
    {
        CommonFunctions comm = new CommonFunctions();
        strid = comm.RemoveSpecialCharacters(strid);
        #region Old code for handling special characters, Commented by 'Imran Gani' on 24-Jun-2013
        //char[] trim = { '=', '\\', ';', '.', ':', ',', '+', '*', '\'', '/', '!', '-' };
        //int pos;

        //strid = strid.ToLower();
        //strid = strid.Trim();

        //while ((pos = strid.IndexOfAny(trim)) >= 0)
        //{
        //    strid = strid.Remove(pos, 1);
        //}
        #endregion
        strid = strid.Trim();
        strid = strid.Replace(' ', '_');
        return strid;
    }

    private string GenerateName(string strid)
    {
        char[] trim = { '=', '\\', ';', '.', ':', ',', '+', '*', '\'', '/' };
        int pos;

        strid = strid.Trim();
        while ((pos = strid.IndexOfAny(trim)) >= 0)
        {
            strid = strid.Remove(pos, 1);
        }
        strid = strid.Trim();
        return strid;
    }

    private bool checkInArrayList(bool bln_name, string inp)
    {
        foreach (DataRow dr in dt_default_col.Rows)
        {
            if (bln_name)
            {
                if (dr["mem_name"].ToString().ToLower() == inp.ToLower())
                    return true;
            }
            else
            {
                if (dr["mem_id"].ToString().ToLower() == inp.ToLower())
                    return true;
            }
        }
        return false;
    }

    private void createDefaultColumns()
    {

        HDDatabase hdd = new HDDatabase();
        dt_default_col = new DataTable();
        DataRow dtr;
        defaultColumns = new ArrayList();

        try
        {
            dt_default_col = hdd.GetDataTable("select * from sy_acr_mem where acr_id='cee69885ce44589c' order by mem_seq");
            dtr = dt_default_col.NewRow();
            dtr.ItemArray = dt_default_col.Rows[0].ItemArray;
            dtr[2] = "af_row_id";
            dtr[4] = "af_row_id";
            dt_default_col.Rows.Add(dtr);

            foreach (DataRow dr in dt_default_col.Rows)
            {
                defaultColumns.Add(dr["mem_id"].ToString());
            }

        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error in createDefaultColumns function. Error: " + e.Message);
        }

        finally
        {
            hdd = null;
        }
    }

    private void GetDataset(DataSet dseObj, string strpageset, DataTable dtaPage, DataTable dtaPageCtrl)
    {
        string strPageId;
        DataRow droPageData;
        HDD = new HDDatabase();
        ScreenReader SR = new ScreenReader();

        ////function added by bala on 18-Nov-2011 for IPP Tech check 
        //CommonFunctions.encodeData(dseObj);

        switch (strpageset.ToLower())
        {
            case "9ec6aa32504a516b": // ps_dobj
            case "cdb0ecf826945479": // ps_dobj_att
            case "e7dd8bdbcd9c6454": // ps_dobj_mas_detail

                for (int i = 0; i < dtaPage.Rows.Count; i++)
                {
                    strPageId = dtaPage.Rows[i]["page_id"].ToString();
                    dseObj.Tables[strPageId].Clear();

                    if (strPageId == "p_dobj")
                    {
                        int p = 0;
                        foreach (ListItem sel in SelChildPage.Items)
                        {
                            p = p + 1;
                            TextBox txt_pgname = (TextBox)DDI.FindControl(frmObj.Controls, "pg_name" + sel.Value);                            
                            droPageData = dseObj.Tables[strPageId].NewRow();
                            droPageData["object_id"] = obj_id.Value;
                            droPageData["object_name"] = txtpsname.Text;
                            droPageData["object_table"] = obj_bu_id.Value;
                            droPageData["af_row_id"] = obj_rowkey.Value;

                            droPageData["associate_notes"] = chk_associate_notes.Checked; // Added by srivatsan on Sep 29 2009 for Notes
                            droPageData["associate_documents"] = chk_associate_documents.Checked; //Added by 'Imran Gani' on 14-Sep-12 for documents
                            droPageData["associate_task"] = chk_associate_task.Checked; // Added by 'Imran Gani' (copied from RakaTech) on 05-Sep-2013 for Task & Alerts

                            if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                            {
                                //droPageData["owner_id"] = ddownerid.SelectedValue;
                                droPageData["owner_id"] = owner_id.Value;
                            }


                            dseObj.Tables[strPageId].Rows.Add(droPageData);
                        }

                    }
                    else if (strPageId == "p_dobj_att")
                    {
                        dseObj.Tables[strPageId].Clear();


                        foreach (ListItem sel in SelChildPage.Items)
                        {
                            int k = 0;
                            HtmlTable hhtObj = (HtmlTable)DDI.FindControl(frmObj.Controls, "tbl_" + sel.Value);
                            TextBox txt_pgname = (TextBox)DDI.FindControl(frmObj.Controls, "pg_name" + sel.Value);
                            HiddenField hih;

                            foreach (HtmlTableRow orow in hhtObj.Rows)
                            {
                                if (k < hhtObj.Rows.Count - 1)
                                {
                                    k = k + 1;
                                    droPageData = dseObj.Tables[strPageId].NewRow();

                                    droPageData["object_id"] = obj_rowkey.Value;

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "att_af_row_id" + k);
                                    droPageData["af_row_id"] = hih.Value == "" ? SR.getHashKey() : hih.Value;

                                    //hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_control_name" + k);
                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_control_id" + k); // Srivatsan for Caption renaming
                                    droPageData["attrib_id"] = GenerateID(hih.Value);

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_control_name" + k);
                                    droPageData["attrib_name"] = GenerateName(hih.Value);

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_desc" + k);
                                    droPageData["attrib_description"] = hih.Value;

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_tooltip" + k);
                                    droPageData["object_tooltip"] = hih.Value;

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "dd_datatype" + k);
                                    droPageData["attrib_data_type"] = hih.Value;

                                    droPageData["attrib_seq"] = k;

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "cb_unique" + k);
                                    droPageData["is_primary"] = hih.Value;

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "dd_typeobject" + k);
                                    bool isEmail = hih.Value.ToUpper() == "EM";

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_size" + k);
                                    droPageData["attrib_size"] = (!isEmail ? hih.Value : (hih.Value == "" ? "255" : (Convert.ToInt32(hih.Value) < 255 ? "255" : hih.Value)));

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "dd_field_type" + k); // Added By 'Imran Gani' on 15-Jul-2013, For Extended field support
                                    droPageData["field_type"] = hih.Value;
                                    
                                    if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                                    {
                                        //droPageData["owner_id"] = ddownerid.SelectedValue;
                                        //droPageData["owner_id"] = owner_id.Value; // Commented By 'Imran Gani' on 23-Jul-2013, For owner of a page control
                                        hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "att_owner_id" + k); // Added By 'Imran Gani' on 23-Jul-2013, For owner of a page control
                                        droPageData["owner_id"] = hih.Value == "" ? Session["user_afrowid"].ToString() : hih.Value;
                                    }


                                    dseObj.Tables[strPageId].Rows.Add(droPageData);
                                }
                            }
                        }
                    }
                }
                break;

            case "50f21749fc3da2ee": // ps_page
            case "534b6e11207db844": // ps_pg_ctr
            case "3b58ce68486728f4": // pg_ctr_droplist // Added by 'Imran Gani' on 11-Dec-2013, for droplist support
            case "91f98d67d57b9830": // ps_pg_event
            case "b8a9ac90d9c3e9ba": // ps_pg_key

                for (int i = 0; i < dtaPage.Rows.Count; i++)
                {
                    strPageId = dtaPage.Rows[i]["page_id"].ToString();
                    if (strPageId == "p_pg")
                    {
                        dseObj.Tables[strPageId].Clear();
                        foreach (ListItem sel in SelChildPage.Items)
                        {
                            TextBox txt_pgname = (TextBox)DDI.FindControl(frmObj.Controls, "pg_name" + sel.Value);
                            TextBox txt_nocont = (TextBox)DDI.FindControl(frmObj.Controls, "Txt_No_Con_" + sel.Value);
                            CheckBox chk_mulrec = (CheckBox)DDI.FindControl(frmObj.Controls, "mul_rec" + sel.Value);
                            CheckBox chk_dis_con = (CheckBox)DDI.FindControl(frmObj.Controls, "dis_con_" + sel.Value);

                            droPageData = dseObj.Tables[strPageId].NewRow();

                            if (droPageData.Table.Columns.Contains("page_desc"))
                                droPageData["page_desc"] = txt_page_tooltip.Text;

                            droPageData["page_id"] = pg_id.Value;
                            droPageData["page_name"] = txtpsname.Text;

                            droPageData["page_table_name"] = obj_bu_id.Value;
                            droPageData["object_id"] = obj_id.Value;

                            droPageData["af_row_id"] = pg_rowkey.Value;

                            droPageData["page_view"] = ddtemp.SelectedValue;

                            droPageData["page_icon"] = ddpageicon.SelectedValue;
                            
                            droPageData["sections_as_tabs"] = chk_sections_as_tabs.Checked; //Added by 'Imran Gani' on 31-May-13 for sections as tabs
                            droPageData["is_next_step_enabled"] = chkenablenextstep.Checked; // Added by srivatsan on Jan 28 2009
                            droPageData["is_rel_info_enabled"] = chkenablerelatedinfo.Checked; // Added by srivatsan on Jan 28 2009

                            droPageData["multiple_recs_page"] = chk_mulrec.Checked;
                            droPageData["control_per_row"] = txt_nocont.Text;
                            droPageData["first_row_caption_only"] = chk_dis_con.Checked;

                            if (dtaPage.Columns.Contains("modified_date"))
                            {
                                droPageData["modified_date"] = System.DateTime.Now;
                            }
                            else if (dtaPage.Columns.Contains("modified_at"))
                            {
                                droPageData["modified_at"] = System.DateTime.Now;
                            }

                            if (dtaPage.Columns.Contains("created_date"))
                            {
                                droPageData["created_date"] = System.DateTime.Now;
                            }
                            else if (dtaPage.Columns.Contains("created_at"))
                            {
                                droPageData["created_at"] = System.DateTime.Now;
                            }

                            if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                            {
                                //droPageData["owner_id"] = ddownerid.SelectedValue;
                                droPageData["owner_id"] = owner_id.Value;
                            }
                            dseObj.Tables[strPageId].Rows.Add(droPageData);
                        }
                    }
                    else if (strPageId == "p_pg_ctr")
                    {
                        dseObj.Tables[strPageId].Clear();

                        foreach (ListItem sel in SelChildPage.Items)
                        {
                            int s = 0;
                            HtmlTable hhtObj = (HtmlTable)DDI.FindControl(frmObj.Controls, "tbl_" + sel.Value);
                            TextBox txt_pgname = (TextBox)DDI.FindControl(frmObj.Controls, "pg_name" + sel.Value);
                            HiddenField hih;

                            foreach (HtmlTableRow orow in hhtObj.Rows)
                            {
                                if (s < hhtObj.Rows.Count - 1)
                                {
                                    s = s + 1;
                                    droPageData = dseObj.Tables[strPageId].NewRow();

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_seq" + s);
                                    droPageData["control_seq"] = hih.Value;

                                    droPageData["page_id"] = pg_rowkey.Value;

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "ctr_af_row_id" + s);
                                    droPageData["af_row_id"] = hih.Value == "" ? SR.getHashKey() : hih.Value;
                                    hih.Value = droPageData["af_row_id"].ToString(); // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.

                                    //hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_control_name" + s);

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_control_id" + s); // Srivatsan for caption renaming
                                    droPageData["control_id"] = GenerateID(hih.Value);

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_control_name" + s);
                                    droPageData["control_name"] = GenerateName(hih.Value);

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "dd_typeobject" + s);
                                    droPageData["control_html"] = hih.Value;

                                    //hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_control_name" + s);
                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_control_id" + s); // Srivatsan for caption renaming
                                    droPageData["control_attrib_id"] = GenerateID(hih.Value);

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "dd_datatype" + s);
                                    droPageData["control_attrib_type"] = hih.Value;

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "dd_databind" + s);
                                    droPageData["control_bind_id"] = hih.Value;

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "dd_inputmask" + s);
                                    droPageData["input_mask_format"] = hih.Value;

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "cb_visible" + s);
                                    droPageData["control_visible"] = hih.Value;

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "cb_readonly" + s);
                                    droPageData["read_only"] = hih.Value;

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "cb_is_section" + s);//ssks
                                    droPageData["is_section"] = hih.Value == "" ? "False" : hih.Value;

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "dd_section_name" + s);//Dhanapal For Section Name on Dec 1 2010
                                    droPageData["section_name"] = hih.Value;

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "cb_is_search" + s);//Dhanapal For Search On Dec 14 2010
                                    droPageData["is_search"] = hih.Value;

                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_default" + s);
                                    droPageData["default_value"] = hih.Value;


                                    if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                                    {
                                        //droPageData["owner_id"] = ddownerid.SelectedValue;
                                        //droPageData["owner_id"] = owner_id.Value; // Commented By 'Imran Gani' on 23-Jul-2013, For owner of a page control
                                        hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "ctr_owner_id" + s); // Added By 'Imran Gani' on 23-Jul-2013, For owner of a page control
                                        droPageData["owner_id"] = hih.Value == "" ? Session["user_afrowid"].ToString() : hih.Value;
                                    }

                                    dseObj.Tables[strPageId].Rows.Add(droPageData);
                                }
                            }

                            if (IsEdit == false)
                            {
                                foreach (DataRow dr in dt_default_col.Rows)
                                {
                                    droPageData = dseObj.Tables[strPageId].NewRow();
                                    droPageData["control_seq"] = dseObj.Tables[strPageId].Rows.Count + 1000;
                                    droPageData["page_id"] = pg_rowkey.Value;
                                    droPageData["af_row_id"] = SR.getHashKey();
                                    droPageData["control_id"] = dr["mem_id"].ToString();
                                    droPageData["control_name"] = dr["mem_name"].ToString();
                                    droPageData["control_html"] = "TB";
                                    droPageData["control_attrib_id"] = dr["mem_id"].ToString();
                                    droPageData["control_attrib_type"] = "TX";
                                    droPageData["control_visible"] = "False";
                                    droPageData["is_section"] = "False";//ssks
                                    droPageData["is_search"] = "False";//Added By Dhanapal On Dec 14 2010 For Search
                                    droPageData["read_only"] = "False";


                                    // Added by srivatsan on June 15 2009 for owner id field
                                    if (droPageData["control_id"].ToString().ToLower() == "owner_id")
                                    {
                                        droPageData["control_visible"] = true;
                                        //droPageData["control_html"] = "DD";
                                        droPageData["control_html"] = "TB";
                                        droPageData["control_bind_id"] = dr["mem_value3"].ToString().Trim();
                                    }


                                    if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                                    {
                                        //droPageData["owner_id"] = ddownerid.SelectedValue;
                                        droPageData["owner_id"] = owner_id.Value;
                                    }

                                    dseObj.Tables[strPageId].Rows.Add(droPageData);
                                }
                            }
                        }
                    }
                    else if (strPageId == "p_pg_ctr_droplist") // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
                    {
                        dseObj.Tables[strPageId].Clear();

                        foreach (ListItem sel in SelChildPage.Items)
                        {
                            int s = 0;
                            HtmlTable hhtObj = (HtmlTable)DDI.FindControl(frmObj.Controls, "tbl_" + sel.Value);
                            TextBox txt_pgname = (TextBox)DDI.FindControl(frmObj.Controls, "pg_name" + sel.Value);
                            HiddenField hih;

                            foreach (HtmlTableRow orow in hhtObj.Rows)
                            {
                                if (s < hhtObj.Rows.Count - 1)
                                {
                                    s = s + 1;
                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "ctr_af_row_id" + s);
                                    string droplist_control_id = hih.Value;
                                    string droplist_owner_id = Session["user_afrowid"].ToString();

                                    if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                                    {
                                        hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "ctr_owner_id" + s); // Added By 'Imran Gani' on 23-Jul-2013, For owner of a page control
                                        droplist_owner_id = hih.Value == "" ? Session["user_afrowid"].ToString() : hih.Value;
                                    }
                                    hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "ta_droplist" + s);
                                    if (hih.Value.Contains("\r\n"))
                                    {
                                        int seq = 0;
                                        string sVal = hih.Value.Replace("\r\n", "|");
                                        foreach (string st in sVal.Split('|'))
                                        {
                                            if (st == "") continue;
                                            if (dseObj.Tables[strPageId].Select("droplist_value = '" + st + "'").Length > 0) continue;
                                            droPageData = dseObj.Tables[strPageId].NewRow();
                                            droPageData["page_id"] = pg_rowkey.Value;
                                            droPageData["control_id"] = droplist_control_id;
                                            droPageData["droplist_value"] = st;
                                            droPageData["droplist_seq"] = seq++;
                                            droPageData["owner_id"] = droplist_owner_id;
                                            dseObj.Tables[strPageId].Rows.Add(droPageData);
                                        }
                                    }
                                    else if (hih.Value != "")
                                    {
                                        droPageData = dseObj.Tables[strPageId].NewRow();
                                        droPageData["droplist_seq"] = 0;
                                        droPageData["droplist_value"] = hih.Value;
                                        droPageData["page_id"] = pg_rowkey.Value;
                                        droPageData["control_id"] = droplist_control_id;
                                        droPageData["owner_id"] = droplist_owner_id;
                                        dseObj.Tables[strPageId].Rows.Add(droPageData);
                                    }
                                }
                            }
                        }
                        if (dseObj.Tables[strPageId].Rows.Count == 0 && isDroplistExists)
                        {
                            droPageData = dseObj.Tables[strPageId].NewRow();
                            droPageData["droplist_seq"] = 0;
                            droPageData["droplist_value"] = "";
                            droPageData["page_id"] = pg_rowkey.Value;
                            droPageData["control_id"] = "";
                            droPageData["owner_id"] = Session["user_afrowid"].ToString();
                            dseObj.Tables[strPageId].Rows.Add(droPageData);
                        }
                    }
                    else if (strPageId == "p_pg_key")
                    {
                    }
                    else if (strPageId == "p_pg_evnt")
                    {
                    }
                }
                break;

            case "b3ef063b174e4ccc": // ps_pageset
            case "a40f400c6424ef4e": // ps_pgs_mem
            case "be2f0230028f06a6": // ps_pgs_srh
            case "d0faefe8b944568b": // pgs_mode // Added By Dhanapal ON DEC232010
            case "e3800174ff18ccb0": // pgs_mode_fields // Added By Dhanapal ON DEC232010

                for (int i = 0; i < dtaPage.Rows.Count; i++)
                {
                    strPageId = dtaPage.Rows[i]["page_id"].ToString();

                    dseObj.Tables[strPageId].Clear();
                    if (strPageId == "p_pgs")
                    {
                        droPageData = dseObj.Tables[strPageId].NewRow();
                        droPageData["pageset_id"] = txtpsid.Text;
                        droPageData["pageset_name"] = txtpsname.Text;
                        droPageData["Pageset_template"] = ddtemp.Text;
                        droPageData["af_row_id"] = ps_rowkey.Value;

                        if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                        {
                            //droPageData["owner_id"] = ddownerid.SelectedValue;
                            droPageData["owner_id"] = owner_id.Value;
                        }

                        dseObj.Tables[strPageId].Rows.Add(droPageData);
                    }
                    else if (strPageId == "p_pgs_mem")
                    {
                        int j = 0;
                        foreach (ListItem sel in SelChildPage.Items)
                        {
                            j = j + 1;
                            TextBox txt_pgname = (TextBox)DDI.FindControl(frmObj.Controls, "pg_name" + sel.Value);

                            droPageData = dseObj.Tables[strPageId].NewRow();
                            droPageData["pageset_id"] = ps_rowkey.Value;
                            droPageData["page_id"] = pg_id.Value;
                            droPageData["page_seq"] = j;
                            droPageData["page_name"] = txtpsname.Text;
                            droPageData["object_id"] = obj_id.Value;
                            if (j == 1)
                                droPageData["is_master"] = "True";
                            droPageData["af_row_id"] = SR.getHashKey();


                            if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                            {
                                //droPageData["owner_id"] = ddownerid.SelectedValue;
                                droPageData["owner_id"] = owner_id.Value;
                            }

                            dseObj.Tables[strPageId].Rows.Add(droPageData);
                        }
                    }

                    else if (strPageId == "p_pgs_srh")
                    {
                        int l = 0;
                        foreach (ListItem sel in SelChildPage.Items)
                        {
                            int k = 0;
                            HiddenField hih;
                            HtmlTable hhtObj = (HtmlTable)DDI.FindControl(frmObj.Controls, "tbl_" + sel.Value);
                            TextBox txt_pgname = (TextBox)DDI.FindControl(frmObj.Controls, "pg_name" + sel.Value);

                            foreach (HtmlTableRow orow in hhtObj.Rows)
                            {
                                if (k < hhtObj.Rows.Count - 1)
                                {
                                    k = k + 1;

                                    HiddenField chkBox1 = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "cb_list" + k);
                                    HiddenField chkBox2 = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "cb_filter" + k);

                                    if ((chkBox1.Value.ToLower() == "true") || (chkBox2.Value.ToLower() == "true"))
                                    {
                                        l = l + 1;
                                        droPageData = dseObj.Tables[strPageId].NewRow();
                                        droPageData["pageset_id"] = ps_rowkey.Value;
                                        droPageData["search_seq"] = l;

                                        // Added by srivatsan for Setting control sequence in list page
                                        hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_seq" + k);
                                        string seqvalue = hih.Value;
                                        if (hih.Value.Trim() == "")
                                        {
                                            seqvalue = "1";
                                        }
                                        droPageData["search_seq"] = seqvalue;


                                        droPageData["page_id"] = pg_id.Value;

                                        hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_control_id" + k); // Srivatsan for caption renaming
                                        droPageData["search_attrib_id"] = GenerateID(hih.Value);
                                        hih = (HiddenField)DDI.FindControl(frmObj.Controls, sel.Value + "txt_control_name" + k);
                                        droPageData["search_attrib_name"] = GenerateName(hih.Value);
                                        droPageData["list_flag"] = chkBox1.Value;
                                        droPageData["quick_search"] = chkBox2.Value;
                                        droPageData["af_row_id"] = SR.getHashKey();

                                        if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                                        {
                                            //droPageData["owner_id"] = ddownerid.SelectedValue;
                                            droPageData["owner_id"] = owner_id.Value;
                                        }

                                        dseObj.Tables[strPageId].Rows.Add(droPageData);
                                    }
                                }
                            }
                        }
                    }

                    else if (strPageId == "p_pgs_mode") //Added By Dhanapal ON DEC232010
                    {
                        if (chkModeValue.Checked == false && chkCategoryValue.Checked == false && ChkDatasheet.Checked == false) //Changed By Dhanapal On Jan 20 2011 // Modified by 'Imran Gani' (copied from RakaTech) on 27-May-2014, for Datasheet
                            continue;

                        if (chkModeValue.Checked == true)
                        {
                            droPageData = dseObj.Tables[strPageId].NewRow();

                            droPageData["pageset_id"] = ps_rowkey.Value;
                            droPageData["af_row_id"] = ps_mode_rowkey.Value;
                            droPageData["mode"] = "TV";
                            if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                            {
                                //droPageData["owner_id"] = ddownerid.SelectedValue;
                                droPageData["owner_id"] = owner_id.Value;
                            }
                            dseObj.Tables[strPageId].Rows.Add(droPageData);
                        }

                        if (chkCategoryValue.Checked == true)
                        {

                            droPageData = dseObj.Tables[strPageId].NewRow();

                            droPageData["pageset_id"] = ps_rowkey.Value;
                            droPageData["af_row_id"] = ps_mode_category_rowkey.Value;
                            droPageData["mode"] = "CV";
                            if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                            {
                                //droPageData["owner_id"] = ddownerid.SelectedValue;
                                droPageData["owner_id"] = owner_id.Value;
                            }
                            dseObj.Tables[strPageId].Rows.Add(droPageData);

                        }

                        if (ChkDatasheet.Checked == true) // Added by 'Imran Gani' (copied from RakaTech) on 27-May-2014, for Datasheet
                        {
                            droPageData = dseObj.Tables[strPageId].NewRow();

                            droPageData["pageset_id"] = ps_rowkey.Value;
                            droPageData["af_row_id"] = ps_mode_datasheet_rowkey.Value;
                            droPageData["mode"] = "DS";
                            if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                            {
                                //droPageData["owner_id"] = ddownerid.SelectedValue;
                                droPageData["owner_id"] = owner_id.Value;
                            }
                            dseObj.Tables[strPageId].Rows.Add(droPageData);
                        }
                    }

                    else if (strPageId == "p_pgs_mode_fields") //Added By Dhanapal ON DEC232010
                    {
                        HiddenField hih;
                        if (chkModeValue.Checked == false && chkCategoryValue.Checked == false) //If the Tree View in Unchecked Dont Add in Dataset
                            continue;
                        if (chkModeValue.Checked == true)
                        {
                            droPageData = dseObj.Tables[strPageId].NewRow(); //For Parent Row

                            droPageData["field_type"] = "PARENT_NODE";
                            droPageData["field"] = ddlParentField.SelectedValue.ToString();
                            droPageData["mode_id"] = ps_mode_rowkey.Value;

                            hih = (HiddenField)DDI.FindControl(frmObj.Controls, "hdnParentfield");
                            droPageData["af_row_id"] = hih.Value == "" ? SR.getHashKey() : hih.Value;

                            //droPageData["af_row_id"] = SR.getHashKey();


                            if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                            {
                                //droPageData["owner_id"] = ddownerid.SelectedValue;
                                droPageData["owner_id"] = owner_id.Value;
                            }

                            dseObj.Tables[strPageId].Rows.Add(droPageData);

                            droPageData = dseObj.Tables[strPageId].NewRow(); //For Child Row

                            droPageData["field_type"] = "CHILD_NODE";
                            droPageData["field"] = ddlChildField.SelectedValue.ToString();
                            droPageData["mode_id"] = ps_mode_rowkey.Value;

                            hih = (HiddenField)DDI.FindControl(frmObj.Controls, "hdnChildfield");
                            droPageData["af_row_id"] = hih.Value == "" ? SR.getHashKey() : hih.Value;

                            if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                            {
                                //droPageData["owner_id"] = ddownerid.SelectedValue;
                                droPageData["owner_id"] = owner_id.Value;
                            }

                            dseObj.Tables[strPageId].Rows.Add(droPageData);
                        }
                        if (chkCategoryValue.Checked == true)
                        {

                            droPageData = dseObj.Tables[strPageId].NewRow(); //For Child Row

                            droPageData["field_type"] = "GROUPING";
                            droPageData["field"] = ddlCategoryField.SelectedValue.ToString();
                            droPageData["mode_id"] = ps_mode_category_rowkey.Value;

                            hih = (HiddenField)DDI.FindControl(frmObj.Controls, "hdnCategoryField");
                            droPageData["af_row_id"] = hih.Value == "" ? SR.getHashKey() : hih.Value;

                            if (dseObj.Tables[strPageId].Columns.Contains("owner_id"))
                            {
                                //droPageData["owner_id"] = ddownerid.SelectedValue;
                                droPageData["owner_id"] = owner_id.Value;
                            }

                            dseObj.Tables[strPageId].Rows.Add(droPageData);

                        }
                    }

                  
                }
                break;
        }
    }

    void tblbtn_Click(object sender, ImageClickEventArgs e)
    {
        if (GlobalValues.loadeventwizard == true)
        {
            GetPageEventRows();
        }
    }

    void tblremovebtn_Click(object sender, EventArgs e)
    {
        if (GlobalValues.loadwizard == true)
        {
            LoadWizard(true);
        }

        if (GlobalValues.loadchildwizard == true)
        {
            LoadWizardMasterFields();
        }

        if (GlobalValues.loadeventwizard == true)
        {
            LoadWizardPageEvents();
        }
    }
    public string DuplicateRows(DataTable dTable, string colName)
    {
        Hashtable hTable = new Hashtable();
        string duplicateList = "";

        foreach (DataRow drow in dTable.Rows)
        {
            //if (drow[colName].ToString() != "")
            //{
            if (hTable.ContainsKey(drow[colName]))
            {
                duplicateList = duplicateList + drow[colName].ToString() + ",";
            }
            else
            {
                hTable.Add(drow[colName], string.Empty);
            }
            //}
            //else
            //{

            //}
        }

        if (duplicateList.Trim().Length > 0)
        {
            duplicateList = duplicateList.Substring(0, duplicateList.Length - 1);
        }

        return duplicateList;
    }

    private void ModifyDataSets()
    {
        HDD = new HDDatabase();
        DataTable dt_obj_att_old;
        DataRow droPageData;

        if (IsEdit && !IsCopy)
        {
            dt_obj_att_old = HDD.GetDataTable("Select * from sy_pgs_mem where pageset_id ='" + ps_rowkey.Value + "'");
            foreach (DataRow dr in dsePagesetInputInfo.Tables["p_pgs_mem"].Rows)
            {
                DataRow[] drr = dt_obj_att_old.Select("page_id = '" + dr["page_id"].ToString().Replace("'", "''") + "'");
                if (drr.Length > 0)
                    dr["af_row_id"] = drr[0]["af_row_id"];
            }

            dt_obj_att_old = HDD.GetDataTable("Select * from sy_pgs_srh where pageset_id ='" + ps_rowkey.Value + "'");
            foreach (DataRow dr in dsePagesetInputInfo.Tables["p_pgs_srh"].Rows)
            {
                string seq = dr["search_seq"].ToString();
                if (seq.Trim() == "")
                {
                    seq = " ";
                }
                DataRow[] drr = dt_obj_att_old.Select("page_id = '" + dr["page_id"].ToString().Replace("'", "''") + "' and search_seq = '" + seq + "'");
                //DataRow[] drr = dt_obj_att_old.Select("page_id = '" + dr["page_id"].ToString().Replace("'", "''") + "' and search_seq = '" + dr["search_seq"] + "'");
                if (drr.Length > 0)
                    dr["af_row_id"] = drr[0]["af_row_id"];
            }
        }

        foreach (DataRow dr in dt_default_col.Rows)
        {
            DataRow[] drobj = dseObjectInputInfo.Tables["p_dobj_att"].Select("attrib_name = '" + dr["mem_name"].ToString() + "'");
            if (drobj.Length > 0)
            {
                drobj[0]["attrib_id"] = dr["mem_id"].ToString();
            }
            DataRow[] drpg = dsePageInputInfo.Tables["p_pg_ctr"].Select("control_name = '" + dr["mem_name"].ToString() + "'");
            if (drpg.Length > 0)
            {
                drpg[0]["control_id"] = dr["mem_id"].ToString();
                drpg[0]["control_attrib_id"] = dr["mem_id"].ToString();
            }
        }

        if (IsCopy)
        {
            for (int i = 0; i < defaultColumns.Count; i++)
            {
                if (dseObjectInputInfo.Tables["p_dobj_att"].Select("attrib_id = '" + defaultColumns[i].ToString().ToLower() + "'").Length > 0)
                    dseObjectInputInfo.Tables["p_dobj_att"].Rows.Remove(dseObjectInputInfo.Tables["p_dobj_att"].Select("attrib_id = '" + defaultColumns[i].ToString().ToLower() + "'")[0]);
            }
        }

        foreach (DataRow dr in dseObjectInputInfo.Tables["p_dobj_mas_detail"].Rows)
        {
            droPageData = dsePageInputInfo.Tables["p_pg_ctr"].NewRow();

            droPageData["af_row_id"] = dr["pg_af_row_id"].ToString();
            droPageData["page_id"] = pg_rowkey.Value;
            droPageData["control_id"] = GenerateID(dr["attrib_id"].ToString());
            droPageData["control_seq"] = System.DBNull.Value;
            droPageData["control_name"] = GenerateName(dr["attrib_name"].ToString());
            droPageData["control_html"] = "TB";
            droPageData["control_attrib_id"] = dr["attrib_id"].ToString();
            droPageData["control_attrib_type"] = "TX";
            droPageData["control_visible"] = "True";
            droPageData["is_section"] = "False";//ssks
            droPageData["is_search"] = "False";//Added By Dhanapal On Dec 14 2010 FOr Search
            droPageData["is_seq_control"] = "False";
            droPageData["read_only"] = "False";

            dsePageInputInfo.Tables["p_pg_ctr"].Rows.Add(droPageData);
        }

        if (dseObjectInputInfo.Tables["p_dobj_att"].Select("is_primary = 'True'").Length > 1)
        {
            dseObjectInputInfo.Tables["p_dobj"].Rows[0]["is_composite"] = true;
        }
    }

    private void DefaultColumnUpdate()
    {
        string strPageId = "";
        string[,] pagearr = pagearr = new string[,] 
            {
                {"Object", "p_dobj"},
                {"Object", "p_dobj_att"}, 
                {"Object", "p_dobj_mas_detail"}, 

                {"Page", "p_pg"},
                {"Page", "p_pg_ctr"},
                {"Page", "p_pg_evnt"},
                {"Page", "p_pg_key"},

                {"Pageset", "p_pgs"},
                {"Pageset", "p_pgs_mem"},
                {"Pageset", "p_pgs_srh"},

                {"Pageset", "p_pgs_mode"}, //Added By dhanapal ON DEC232010
                {"Pageset", "p_pgs_mode_fields"}
            };

        for (int j = 0; j <= pagearr.GetUpperBound(0); j++)
        {
            strPageId = pagearr[j, 1].ToString();
            foreach (DataRow dr in dseInputInfo.Tables[strPageId].Rows)
            {
                if (dseInputInfo.Tables[strPageId].Columns.Contains("modified_date"))
                {
                    dr["modified_date"] = DateTime.Now.ToString();
                }
                else if (dseInputInfo.Tables[strPageId].Columns.Contains("modified_at"))
                {
                    dr["modified_at"] = DateTime.Now.ToString();
                }

                //if ((IsEdit) && (!IsCopy))
                //{
                //}
                //else
                //{
                if (dseInputInfo.Tables[strPageId].Columns.Contains("created_date"))
                {
                    dr["created_date"] = DateTime.Now.ToString();
                }
                else if (dseInputInfo.Tables[strPageId].Columns.Contains("created_at"))
                {
                    dr["created_at"] = DateTime.Now.ToString();
                }
                //}

                if (dseInputInfo.Tables[strPageId].Columns.Contains("modified_by"))
                {
                    dr["modified_by"] = HttpContext.Current.Session["user_afrowid"].ToString();
                }

                //uncommented by srivatsan
                if ((IsEdit) && (!IsCopy))
                {
                }
                else
                {
                    if (dseInputInfo.Tables[strPageId].Columns.Contains("created_by"))
                    {
                        dr["created_by"] = HttpContext.Current.Session["user_afrowid"].ToString();
                    }
                }
                // Added by srivatsan on June 15 2009 for owner id field
                if (dseInputInfo.Tables[strPageId].Columns.Contains("owner_id"))
                {
                    //dr["owner_id"] = HttpContext.Current.Session["user_afrowid"].ToString();
                    //dr["owner_id"] = ddownerid.SelectedValue;
                    //dr["owner_id"] = owner_id.Value; // Commented By 'Imran Gani' on 23-Jul-2013, For owner of a page control
                }//



            }
        }
    }

    private bool MergePageset(ref string message)
    {
        bool blnStatus = true;
        DataSet dsetempInfo;
        ScreenReader SR = new ScreenReader();
        string strPagesetRowID = "";
        string[,] pagearr = pagearr = new string[,] 
            {
                {"Object", "9ec6aa32504a516b"}, // ps_dobj
                {"Object", "cdb0ecf826945479"}, // ps_dobj_att
                {"Object", "e7dd8bdbcd9c6454"}, // ps_dobj_mas_detail

                {"Page", "50f21749fc3da2ee"}, // ps_page
                {"Page", "534b6e11207db844"}, // ps_pg_ctr
                {"Page", "3b58ce68486728f4"}, // pg_ctr_droplist // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
                {"Page", "91f98d67d57b9830"}, // ps_pg_event
                {"Page", "b8a9ac90d9c3e9ba"}, // ps_pg_key

                {"Pageset", "b3ef063b174e4ccc"}, // ps_pageset
                {"Pageset", "a40f400c6424ef4e"}, // ps_pgs_mem
                {"Pageset", "be2f0230028f06a6"}, // ps_pgs_srh
                
                {"Pageset", "d0faefe8b944568b"}, // pgs_mode //Added By dhanapal ON DEC232010
                {"Pageset", "e3800174ff18ccb0"} // pgs_mode_fields
            };
        PageInfoLoad PIL = new PageInfoLoad();
        dsePageInfo = new DataSet();
        dseInputInfo = new DataSet();

        dsePageInfo = PIL.GetPageSetPageCtrlInfo("9ec6aa32504a516b"); // ps_dobj

        for (int j = 1; j <= pagearr.GetUpperBound(0); j++)
        {
            dsetempInfo = new DataSet();
            strPagesetRowID = pagearr[j, 1].ToString();
            dsetempInfo = PIL.GetPageSetPageCtrlInfo(strPagesetRowID);
            dsePageInfo.Tables["Page"].Merge(dsetempInfo.Tables["Page"]);
            dsePageInfo.Tables["PageCtrl"].Merge(dsetempInfo.Tables["PageCtrl"]);
            dsePageInfo.Tables["PageKeys"].Merge(dsetempInfo.Tables["PageKeys"]);
        }

        dseInputInfo.Merge(dseObjectInputInfo, true);
        dseInputInfo.Merge(dsePageInputInfo, true);
        dseInputInfo.Merge(dsePagesetInputInfo, true);

        //function added by Sampath on 17-Nov-2011 for IPP Tech check 
        //CommonFunctions.encodeData(dseInputInfo);

        DefaultColumnUpdate();

        if (IsCopy)
        {
            foreach (DataTable dt in dseInputInfo.Tables)
            {
                if ((dt.TableName != "p_dobj") && (dt.TableName != "p_pg") && (dt.TableName != "p_pgs"))
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        dr["af_row_id"] = SR.getHashKey();
                    }
                }
            }
        }

        if (dseInputInfo.Tables["p_dobj_att"].Rows.Count > 0)
        {
            if (dseInputInfo.Tables["p_pgs_srh"].Rows.Count > 0)
            {
                if (dseInputInfo.Tables["p_pgs_srh"].Select("list_flag = True").Length > 0)
                {
                    if (dseInputInfo.Tables["p_dobj_mas_detail"].Select("master_obj = ''").Length > 0)
                    {
                        blnStatus = false;
                        message = "Select a master object for master relationship. ";
                        //lbl_message.Text = "Select a master object for master relationship. ";
                        //lbl_message2.Text = "Select a master object for master relationship. ";
                        //lbl_message3.Text = "Select a master object for master relationship. ";
                    }
                    else
                    {
                        string duplicateList = DuplicateRows(dseInputInfo.Tables["p_pg_ctr"], "control_id");

                        if (duplicateList.Trim().Length > 0)
                        {
                            blnStatus = false;
                            message = "The followings controls are duplicated - " + duplicateList;
                            //lbl_message.Text = "The followings controls are duplicated - " + duplicateList;
                            //lbl_message2.Text = "The followings controls are duplicated - " + duplicateList;
                            //lbl_message3.Text = "The followings controls are duplicated - " + duplicateList;
                        }
                        else
                        {
                            string validate = validateTree(dseInputInfo); //Added By Dhanapal TO Validate the Tree View Input Info

                            if (validate != "")
                            {
                                blnStatus = false;
                                message = validate;
                            }
                            else
                            {

                                blnStatus = InsertTableRows(dsePageInfo, dseInputInfo);
                            }
                        }
                    }
                }
                else
                {
                    blnStatus = false;
                    message = "Select a control for the List View. ";
                    //lbl_message.Text = "Select a control for the List View. ";
                    //lbl_message2.Text = "Select a control for the List View. ";
                    //lbl_message3.Text = "Select a control for the List View. ";

                }
            }
            else
            {
                blnStatus = false;
                message  = "Select a control for the List View. ";
                //lbl_message.Text = "Select a control for the List View. ";
                //lbl_message2.Text = "Select a control for the List View. ";
                //lbl_message3.Text = "Select a control for the List View. ";
            }
        }
        else
        {
            blnStatus = false;
            message = "Page should have at least a control. ";
            //lbl_message.Text = "Page should have at least a control. ";
            //lbl_message2.Text = "Page should have at least a control. ";
            //lbl_message3.Text = "Page should have at least a control. ";
        }
        return blnStatus;
    }

    
    private string validateTree(DataSet dseInputInfo) //Added By Dhanapal For Tree View Validation Control
    {
        DataRow[] dr = dseInputInfo.Tables["p_pgs_mode"].Select("pageset_id = '" + ps_rowkey.Value + "' and mode = 'TV'"); 
        if (dr.Length > 0)
        {
            string strModeId = dr[0]["af_row_id"].ToString();
            DataRow[] drNodes = dseInputInfo.Tables["p_pgs_mode_fields"].Select("mode_id = '" + strModeId + "'");
            if (drNodes.Length > 0)
            {
                string emptycol = "";
                string samecol = "";
                ArrayList arlNodename = new ArrayList();
                foreach (DataRow drr in drNodes)
                {
                    if (drr["field"].ToString().ToLower() == "")
                    {
                        emptycol += drr["field_type"].ToString() + ",";
                    }

                    if (!arlNodename.Contains(drr["field"].ToString()))
                    {
                        arlNodename.Add(drr["field"].ToString());
                    }
                    else
                    {
                        samecol += drr["field"].ToString();
                        //return " Parent and  Child Node of Tree View is Same ";
                    }

                }
                if (emptycol != "")
                {
                    return "Tree view should have a parent and child field selected.";
                }
                else if (samecol != "")
                {

                    return "Tree view should not have a same parent and child field selected.";
                }
                
                //DataTable dt = dseInputInfo.Tables["p_pg_ctr"].Select("page_id = '" + pg_rowkey.Value + "'");

                foreach (DataRow drr in drNodes)
                {
                    DataRow[] drctrl = dseInputInfo.Tables["p_pg_ctr"].Select("page_id = '" + pg_rowkey.Value + "' and  control_id = '" + drr["field"].ToString() + "'");
                    if (drctrl.Length < 0)
                    {
                        return "Tree view Parent and child node contains non existing control id";
                    }
                    
                }

            }

        }

        DataRow[] drow = dseInputInfo.Tables["p_pgs_mode"].Select("pageset_id = '" + ps_rowkey.Value + "' and mode = 'CV'");
        if (drow.Length > 0)
        {
            string strCategryModeId = drow[0]["af_row_id"].ToString();
            DataRow[] drrNodes = dseInputInfo.Tables["p_pgs_mode_fields"].Select("mode_id = '" + strCategryModeId + "'");
            if (drrNodes.Length > 0)
            {
                foreach (DataRow drCatgfield in drrNodes)
                {
                    if (drCatgfield["field"].ToString().ToLower() == "")
                    {
                        return "Category view should have a field selected.";
                    }
                }
            }
           
        }
        return "";
    }


    private bool InsertTableRows(DataSet dsePageInfo, DataSet dseInputInfo)
    {
        Master MA = new Master();
        bool blnStatus = true;
        string strErrMessage = "";
        string strprocess = "";

        if (IsEdit && !IsCopy)
        {
            strprocess = "UPDATE";
        }
        else
        {
            strprocess = "INSERT";
        }

        try
        {
            if (!(MA.ProcessOperation(dsePageInfo, dseInputInfo, strprocess)))
            {
                blnStatus = false;
            }
            else
            {

            }
        }
        catch (Exception ex)
        {
            blnStatus = false;
            strErrMessage = ex.Message;
            LogWriter.WriteLog("Error : " + strErrMessage);
        }
        return blnStatus;
    }

    private void FinishPage()
    {
        string message3 = "";
        if (validateOwnerid(ref message3))
        {
            string message = "";
            if (validateDataType(ref message))
            {
                GetDataset();
                GetPageChildRows();
                GetPageEventRows();

                ModifyDataSets();

                string message2 = "";
                if (MergePageset(ref message2))
                {
                    dseObjectInputInfo = null;
                    dsePageInputInfo = null;
                    dsePagesetInputInfo = null;

                    Session["dseObjectInputInfo"] = null;
                    Session["dsePageInputInfo"] = null;
                    Session["dsePagesetInputInfo"] = null;

                    createDefaultMenu();

                    Response.Redirect("DisplayGrid.aspx?mn=" + HDD.GetColumnValue("sy_mnu", "af_row_id", "pageset_id = 'b3ef063b174e4ccc' and pageset_url = 'PageWizard.aspx'") + "&pgs_id=b3ef063b174e4ccc"); // pageset_id and pgs_id=ps_pageset
                }
                else
                {
                    lblMessage.Text = wrapItAsMessage((IsEdit == true ? "Updation" : "Insertion") + " not successful. " + message2, true);
                    //lbl_message.Text = (IsEdit == true ? "Updation" : "Insertion") + " not successful. " + lbl_message.Text;
                    //lbl_message2.Text = (IsEdit == true ? "Updation" : "Insertion") + " not successful. " + lbl_message2.Text;
                    //lbl_message3.Text = (IsEdit == true ? "Updation" : "Insertion") + " not successful. " + lbl_message3.Text;
                }
            }
            else
            {
                //lbl_message2.Text = "&nbsp;<img src='Images/error.gif' border='0'>&nbsp;" + (IsEdit == true ? "Updation" : "Insertion") + " not successful. " + lbl_message2.Text;
                lblMessage.Text = wrapItAsMessage("&nbsp;<img src='Images/error.gif' border='0'>&nbsp;" + (IsEdit == true ? "Updation" : "Insertion") + " not successful. " + message,true);
            }
        }
        else
        {
            lblMessage.Text = wrapItAsMessage((IsEdit == true ? "Updation" : "Insertion") + " not successful. " + message3, true);
            //lbl_message.Text = (IsEdit == true ? "Updation" : "Insertion") + " not successful. " + lbl_message.Text;
            //lbl_message2.Text = (IsEdit == true ? "Updation" : "Insertion") + " not successful. " + lbl_message2.Text;
            //lbl_message3.Text = (IsEdit == true ? "Updation" : "Insertion") + " not successful. " + lbl_message3.Text;
        }
    }
    private void createDefaultMenu()
    {
        try
        {
            if (IsEdit) return;
            ScreenReader sr = new ScreenReader();
            HDDatabase hdd_acc = new HDDatabase();
            DataTable dtConfigs = new DataTable();
            dtConfigs = hdd_acc.GetDataTable("select * from sy_acr_mem where acr_id='a5878586119ae1fa';");
            if (dtConfigs != null)
            {
                if (dtConfigs.Rows.Count > 0)
                {
                    if (dtConfigs.Select("af_row_id='d2cb685b0242bc2e'")[0]["mem_value1"].ToString().ToLower() == "true")
                    {
                        string parent_menu_id = dtConfigs.Select("af_row_id='c4ccf2b1b2bf4c37'")[0]["mem_value1"].ToString();
                        string strMenuRowId = sr.getHashKey();
                        string menuId = getAutoNumberValue("sy_mnu", "menu_id");
                        string menu_sql = "insert into sy_mnu(af_row_id, menu_id, menu_name, parent_menu_id, pageset_id, " +
                                        "pageset_url_type, menu_seq, is_active, created_by, created_at, modified_at, modified_by,owner_id) " +
                                        " values('" + strMenuRowId + "'," + menuId + ",'" +
                                        txtpsname.Text.Replace("'", "''") + "','" + parent_menu_id + "','" + ps_rowkey.Value + "'," +
                                        "1," + getAutoNumberValue("sy_mnu", "menu_seq") + "," + "1" + ",'" +
                                        HttpContext.Current.Session["user_afrowid"].ToString() + "','" +
                                        DateTime.Now.ToUniversalTime().ToString() + "','" + DateTime.Now.ToUniversalTime().ToString() +
                                        "','" + HttpContext.Current.Session["user_afrowid"].ToString() + "','" + HttpContext.Current.Session["user_afrowid"] + "')";
                        string obj_acc_sql = "insert into sy_obj_acc(af_row_id, role_id, object_id, [read], [create], edit, [delete], " +
                                            "created_by, created_at, modified_at, modified_by,owner_id) values('" +
                                            sr.getHashKey() + "','" + HttpContext.Current.Session["roleid"].ToString() + "','" +
                                            obj_id.Value + "',1,1,1,1,'" + HttpContext.Current.Session["user_afrowid"].ToString() + "','" +
                                            DateTime.Now.ToUniversalTime().ToString() + "','" + DateTime.Now.ToUniversalTime().ToString() +
                                            "','" + HttpContext.Current.Session["user_afrowid"].ToString() + "','" + HttpContext.Current.Session["user_afrowid"] + "')";
                        string menu_acc_sql = "insert into sy_rol_acc(af_row_id, role_id, menu_id, is_accessible, " +
                                                "created_by, created_at, modified_at, modified_by,owner_id) values('" +
                                                sr.getHashKey() + "','" + HttpContext.Current.Session["roleid"].ToString() + "','" +
                                                strMenuRowId + "',1,'" + HttpContext.Current.Session["user_afrowid"].ToString() + "','" +
                                                DateTime.Now.ToUniversalTime().ToString() + "','" + DateTime.Now.ToUniversalTime().ToString() +
                                                "','" + HttpContext.Current.Session["user_afrowid"].ToString() + "','" + HttpContext.Current.Session["user_afrowid"] + "')";

                        if (hdd_acc.ExecuteCmdObj(new SqlCommand(obj_acc_sql)) > 0)
                            if (hdd_acc.ExecuteCmdObj(new SqlCommand(menu_sql)) > 0)
                                hdd_acc.ExecuteCmdObj(new SqlCommand(menu_acc_sql));
                    }
                }
            }
            hdd_acc = null;
            sr = null;
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error in createDefaultMenu. " + e.Message);
        }
    }
    private string getAutoNumberValue(string sObjectTable, string Field)
    {
        HDDatabase HDD = new HDDatabase();
        string sVal = HDD.GetColumnValue("select max([" + Field.Replace("'", "''") + "]) + 1 as AN from [" + sObjectTable.Replace("'", "''") + "]");
        HDD = null;
        sVal = sVal == "" ? "1" : sVal;
        //if (PageRowCount > 1)
        //    sVal = Convert.ToString(Convert.ToInt32(sVal) + PageRowCount - 1);
        return sVal;
    }
    protected void FinishButton_Click(object sender, EventArgs e)
    {
        FinishPage();
    }
    protected void imgbtn_save_Click(object sender, EventArgs e)
    {
        LoadHiddenControls(false);
        GetDataset();

        string duplicateList = DuplicateRows(dsePageInputInfo.Tables["p_pg_ctr"], "control_id");
        if (duplicateList.Trim().Length > 0)
        {
            //lbl_message.Text = "The followings controls are duplicated - " + duplicateList;
            //lbl_message2.Text = "The followings controls are duplicated - " + duplicateList;
            //lbl_message3.Text = "The followings controls are duplicated - " + duplicateList;
            lblMessage.Text = wrapItAsMessage("The followings controls are duplicated - " + duplicateList,true);
        }

    }
    protected void imgbtn_update_Click(object sender, EventArgs e)
    {
        LoadHiddenControls(true);
        GetDataset();

        string duplicateList = DuplicateRows(dsePageInputInfo.Tables["p_pg_ctr"], "control_id");
        if (duplicateList.Trim().Length > 0)
        {
            //lbl_message.Text = "The followings controls are duplicated - " + duplicateList;
            //lbl_message2.Text = "The followings controls are duplicated - " + duplicateList;
            //lbl_message3.Text = "The followings controls are duplicated - " + duplicateList;
            lblMessage.Text = wrapItAsMessage("The followings controls are duplicated - " + duplicateList, true);
        }



    }
    private void getpageicons()
    {
        PageIcons icons = new PageIcons();
        try
        {
            pagewizard.HeaderText = icons.geticontextfrompageset(Request.QueryString["pgs_id"], 2).ToString() + "&nbsp;" + pagewizard.HeaderText;
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error :getpageicons()" + ex.Message);
            pagewizard.HeaderText = "&nbsp;<img src=" + PageIcons.strdefaulticon.ToString() + "></img>&nbsp;";
        }
        finally
        {
            icons = null;
        }
    }
    private bool shownextsteppanel()
    {
        bool result = false;
        try
        {

            if (Session["user_afrowid"] != null)
            {
                if (Session["user_afrowid"].ToString() == "e51e0327224a2eb9")
                {
                    result = true;
                    try
                    {
                        //pagewizard.FindControl("panadvanced").Visible = true;

                        ShowAdditionalCheckboxes();


                    }
                    catch (Exception ex)
                    {
                        //pagewizard.FindControl("panadvanced").Visible = true;
                        ShowAdditionalCheckboxes();
                        LogWriter.WriteLog("Error Pagewizard shownextsteppanel " + ex.Message);
                    }
                }
                else
                {
                    hideAdditionalCheckboxes();
                    //pagewizard.FindControl("panadvanced").Visible = false;
                }
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error shownextsteppanel :" + ex.Message);
        }

        return result;
    }
    private void GetNextStepValues()
    {
        HDDatabase Hdd1 = new HDDatabase();
        try
        {

            if (Request.QueryString["PK"] != null)
            {
                string strsql = "Select sy_pg.is_next_step_enabled as nextstep,sy_pg.is_rel_info_enabled as relatedinfo from sy_pg inner join sy_pgs_mem on sy_pg.page_id = sy_pgs_mem.page_id where sy_pgs_mem.pageset_id  = '" + Request.QueryString["PK"].ToString() + "'";

                try
                {
                    DataTable dt = Hdd1.GetDataTable(strsql);
                    if (dt != null)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            if (dt.Rows[0]["nextstep"].ToString().ToLower() == "true")
                            {
                                chkenablenextstep.Checked = true;
                            }
                            else
                            {
                                chkenablenextstep.Checked = false;
                            }
                            if (dt.Rows[0]["relatedinfo"].ToString().ToLower() == "true")
                            {
                                chkenablerelatedinfo.Checked = true;
                            }
                            else
                            {
                                chkenablerelatedinfo.Checked = false;
                            }
                        }

                    }
                }
                catch (Exception ex)
                {
                    LogWriter.WriteLog("Error GetNextStepValues " + ex.Message);
                }
            }
            else
            {
                chkenablenextstep.Checked = true;
                chkenablerelatedinfo.Checked = true;
            }

        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error GetNextStepValues " + ex.Message);
        }
        finally
        {
            Hdd1 = null;
        }
    }

    private void loadOwneridDropDown() // Added by srivatsan for owner id change
    {
        HDDatabase Hdd = new HDDatabase();
        BindControl BC = new BindControl();
        //DataSet ds = new DataSet();
        DataTable dt = null;
        try
        {
            string strBindRowID = Hdd.GetColumnValue("select mem_value3 from sy_acr_mem where acr_id = 'cee69885ce44589c' and mem_id = 'owner_id'");
            BC.Bind(strBindRowID, ddownerid, ref dt, null);

            if (ddownerid.Items.FindByValue("") == null)
            {
                ddownerid.Items.Insert(0, "");
            }


            if (Session["user_afrowid"].ToString() == "e51e0327224a2eb9")
            {
                if (ddownerid.Items.FindByValue("e51e0327224a2eb9") == null)
                {
                    ddownerid.Items.Add(new ListItem(Session["userid"].ToString(), Session["user_afrowid"].ToString()));
                }
            }
            else
            {
                if (ddownerid.Items.FindByValue("e51e0327224a2eb9") != null)
                {
                    ddownerid.Items.Remove(ddownerid.Items.FindByValue("e51e0327224a2eb9"));
                }
            }

            if (Request.QueryString["PK"] == null)
            {
                ddownerid.SelectedValue = Session["user_afrowid"].ToString();
            }
            if (Request.QueryString["PK"] != null)
            {
                if (Request.QueryString["CPY"] != null)
                {
                    ddownerid.SelectedValue = Session["user_afrowid"].ToString();
                }

            }

        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : loadOwneridDropDown :" + ex.Message);
        }
        finally
        {
            Hdd = null;
            BC = null;
            dt = null;
        }


    }

    private string applysecurity(string sql)
    {

        try
        {
            SecurityFilter objSec = new SecurityFilter();
            string sAFAdmin = objSec.QueryForAFAdmin();
            string sCustodianFilter = objSec.QueryForCustodianFilter();
            if (sCustodianFilter.Trim() != "")
                if (!sCustodianFilter.StartsWith("or"))
                {
                    sAFAdmin += " and " + sCustodianFilter;
                }
                else
                {
                    //if (QuickSearchSQL.Trim() == "")  // if no search exists show all no owner records
                    //{
                    sAFAdmin = "(" + sAFAdmin + " " + sCustodianFilter + ") ";
                    //sAFAdmin += " " + sCustodianFilter;
                    // }
                }

            if (sql.Contains("order by"))
            {
                if (sAFAdmin.Trim() != "")
                {
                    sql = sql.Replace("order by", "where " + sAFAdmin + " order by");
                }
            }
            else
            {
                if (sAFAdmin.Trim() != "")
                {
                    sql = sql + " where " + sAFAdmin;
                }
            }


        }
        catch
        {

        }
        return sql;
    }
    private void CheckForChangeOwner()  // Added by srivatsan to Check if user can change owner
    {
        try
        {
            security sec = new security();
            bool status = false;
            status = sec.getRightsForMRUObjects(HttpContext.Current.Request.QueryString["pgs_id"].ToString(), "change_owner");
            if (status == false)
            {

                txt_owner_id.Enabled = false;
                imgOwnerSearch.Visible = false;
            }
            sec = null;
        }
        catch
        {

        }
    }

    private bool validateOwnerid(ref string message)
    {
        bool status = false;
        BindControl BC = new BindControl();
        DataSet dsBind = new DataSet();
        string sql = BC.GetBindSql("f496930dfe0b690f");
        dsBind = HDD.GetDataset(sql);
        if (dsBind != null)
        {
            if (dsBind.Tables.Count > 0)
            {
                if (dsBind.Tables[0].Rows.Count > 0)
                {
                    if (txt_owner_id.Text != "")
                    {
                        DataRow[] drrbind = dsBind.Tables[0].Select("fld = '" + txt_owner_id.Text.Trim().Replace("'", "''") + "'");

                        if (drrbind.Length > 0)
                        {
                            owner_id.Value = drrbind[0]["val"].ToString();
                            status = true;
                        }
                    }
                    else
                    {
                        owner_id.Value = "";
                        status = true;
                    }
                }
                else
                {
                    owner_id.Value = "";
                    status = true;
                }
            }
        }
        if (status != true)
        {
            //lbl_message.Text = "<img src=\"Images/error.gif\" alt=\"Error\"></img>&nbsp; Error: Invalid data for Owner :" + txt_ownerid.Text;
            //lbl_message.Text = " Invalid data for Owner :" + txt_owner_id.Text;
            //lbl_message2.Text = " Invalid data for Owner :" + txt_owner_id.Text;
            //lbl_message3.Text = " Invalid data for Owner :" + txt_owner_id.Text;
            message = "Invalid data for Owner :" + HttpUtility.HtmlEncode(txt_owner_id.Text);
        }
        return status;

    }
    private bool Convert2Boolean(string input)
    {
        bool status = false;
        try
        {
            if (input.Trim() != "")
            {
                status = Convert.ToBoolean(input);
            }
        }
        catch (Exception ex)
        {
            status = false;
        }
        finally
        {

        }
        return status;

    }

    private void hideAdditionalCheckboxes()
    {
        chkenablenextstep.Visible = false;
        chkenablerelatedinfo.Visible = false;
        lbl_enablenextstep.Visible = false;
        lbl_enablerelatedinfo.Visible = false;
    }

    private void ShowAdditionalCheckboxes()
    {
        chkenablenextstep.Visible = true;
        chkenablerelatedinfo.Visible = true;
        lbl_enablenextstep.Visible = true;
        lbl_enablerelatedinfo.Visible = true;
    }


    private string wrapItAsMessage(string msg, bool isError)
    {
        if (isError)
        {
            if (msg.IndexOf("error.gif") < 0)
                msg = "&nbsp;<img src='Images/error.gif' border='0'>&nbsp;" + msg;
        }
       return "<div class=\"" + (isError == true ? "mbErrorMessage" : "mbMessage") + "\">" + msg + "</div>";
    }

    private string wrapItAsMessageNew(string msg, bool isError)
    {
        return "<div class=\"" + (isError == true ? "mbErrorMessage" : "mbMessage") + "\">" + msg + "</div>";
    }
    protected void owner_id_ValueChanged(object sender, EventArgs e)
    {

    }
    /// <summary>
    /// To set the droplist values for a control.
    /// </summary>
    /// <param name="dtaData">Input data table</param>
    // Added by 'Imran Gani' on 26-Dec-2013, for droplist support.
    private void loadControlDroplist(DataTable dtaData)
    {
        HDDatabase hd = new HDDatabase();
        DataTable dt_droplist = new DataTable();
        try
        {
            dt_droplist = hd.GetDataTable("select * from [sy_pg_ctr_droplist] where [page_id] = '" + pg_rowkey.Value + "';");
            if (dt_droplist.Rows.Count == 0) return;
            isDroplistExists = true;
            foreach (DataRow dr in dtaData.Rows)
            {
                string sDroplistVal = string.Empty;
                foreach (DataRow dr_pl in dt_droplist.Select("control_id = '" + dr["ctr_af_row_id"].ToString() + "'"))
                {
                    if (!string.IsNullOrEmpty(sDroplistVal))
                        sDroplistVal += System.Environment.NewLine;
                    sDroplistVal += dr_pl["droplist_value"].ToString();
                }
                dr["ta_droplist"] = sDroplistVal;
            }
        }
        catch (Exception ex)
        {
            LogWriter.WriteLog("Error : loadControlDroplist :" + ex.Message);
        }
        finally
        {
            dt_droplist.Dispose();
            hd = null;
        }
    }
}
